From 49ebb8dd78b644e61a32d969f89dad62026d16e5 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 18 Feb 2025 10:48:31 -0600 Subject: [PATCH] Add A Better Way To Reload ZSH Configuration as a ZSH TIL --- README.md | 3 +- ...-better-way-to-reload-zsh-configuration.md | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 zsh/a-better-way-to-reload-zsh-configuration.md diff --git a/README.md b/README.md index 37f2103..525decf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1593 TILs and counting..._ +_1594 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -1884,6 +1884,7 @@ See some of the other learning resources I work on: ### Zsh +- [A Better Way To Reload ZSH Configuration](zsh/a-better-way-to-reload-zsh-configuration.md) - [Add To The Path Via Path Array](zsh/add-to-the-path-via-path-array.md) - [Link A Scalar To An Array](zsh/link-a-scalar-to-an-array.md) - [Use A Space To Exclude Command From History](zsh/use-a-space-to-exclude-command-from-history.md) diff --git a/zsh/a-better-way-to-reload-zsh-configuration.md b/zsh/a-better-way-to-reload-zsh-configuration.md new file mode 100644 index 0000000..0c55837 --- /dev/null +++ b/zsh/a-better-way-to-reload-zsh-configuration.md @@ -0,0 +1,35 @@ +# A Better Way To Reload ZSH Configuration + +I have an alias in my `~/.zshrc` that I set up to make it easy to "reload" my +ZSH configuration. This is handy if I'm iterating on some changes to my +`~/.zshrc` file and need verify them as I go. + +```bash +alias reload='source ~/.zshrc' +``` + +With this alias, I can call `reload` from the terminal and the latest version +of my configuration (according to the `~/.zshrc` file) will be loaded for that +shell instance. + +This has some downsides. It doesn't account for the other kinds of files that +contribute to your shell configuration (e.g. `~/.zprofile`) and it can lead to +duplicate values in your `PATH` and init scripts being run an additional time. + +A better way is to use: + +```bash +$ omz reload +``` + +This is [a wrapper call around `exec +zsh`](https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/cli.zsh#L669-L677), +which restarts the `zsh` process. It also clears the completion cache. + +I've since updated my `~/.zshrc` alias for `reload`: + +```bash +alias reload='omz reload' +``` + +[source](https://batsov.com/articles/2022/09/15/reload-zsh-configuration/)