From 9a7c56dcddfd007499bc59560c1de282611f6813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 26 Oct 2016 20:04:14 +0200 Subject: [PATCH 1/4] zsh_reload: fix code style and indent with tabs --- plugins/zsh_reload/zsh_reload.plugin.zsh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/zsh_reload/zsh_reload.plugin.zsh b/plugins/zsh_reload/zsh_reload.plugin.zsh index cde9ebec..e3aed5d7 100644 --- a/plugins/zsh_reload/zsh_reload.plugin.zsh +++ b/plugins/zsh_reload/zsh_reload.plugin.zsh @@ -1,13 +1,11 @@ -# reload zshrc -function src() -{ - local cache=$ZSH_CACHE_DIR - autoload -U compinit zrecompile - compinit -d "$cache/zcomp-$HOST" +src() { + local cache="$ZSH_CACHE_DIR" + autoload -U compinit zrecompile + compinit -d "$cache/zcomp-$HOST" - for f in ~/.zshrc "$cache/zcomp-$HOST"; do - zrecompile -p $f && command rm -f $f.zwc.old - done + for f in ~/.zshrc "$cache/zcomp-$HOST"; do + zrecompile -p $f && command rm -f $f.zwc.old + done - source ~/.zshrc + source ~/.zshrc } From 8706c8eb64c7eb40fe1acda30404ebc24fdb7f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 26 Oct 2016 20:09:08 +0200 Subject: [PATCH 2/4] zsh_reload: ignore insecure compinit files --- plugins/zsh_reload/zsh_reload.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/zsh_reload/zsh_reload.plugin.zsh b/plugins/zsh_reload/zsh_reload.plugin.zsh index e3aed5d7..b3a0094d 100644 --- a/plugins/zsh_reload/zsh_reload.plugin.zsh +++ b/plugins/zsh_reload/zsh_reload.plugin.zsh @@ -1,7 +1,7 @@ src() { local cache="$ZSH_CACHE_DIR" autoload -U compinit zrecompile - compinit -d "$cache/zcomp-$HOST" + compinit -i -d "$cache/zcomp-$HOST" for f in ~/.zshrc "$cache/zcomp-$HOST"; do zrecompile -p $f && command rm -f $f.zwc.old From 405b8f220abe35eabc408566d7c4442a3a8149db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 26 Oct 2016 20:05:57 +0200 Subject: [PATCH 3/4] zsh_reload: use `exec zsh` instead of `source ~/.zshrc` `source ~/.zshrc` is a bad practice, it doesn't make sure that the full zsh session is reloaded and it may have side effects. Use `$SHELL` as the path to zsh if it exists (this will fix edge cases where the zsh used is not the first on $PATH). Otherwise, use `zsh`. --- plugins/zsh_reload/zsh_reload.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/zsh_reload/zsh_reload.plugin.zsh b/plugins/zsh_reload/zsh_reload.plugin.zsh index b3a0094d..51048ba9 100644 --- a/plugins/zsh_reload/zsh_reload.plugin.zsh +++ b/plugins/zsh_reload/zsh_reload.plugin.zsh @@ -7,5 +7,6 @@ src() { zrecompile -p $f && command rm -f $f.zwc.old done - source ~/.zshrc + # Use $SHELL if available; remove leading dash if login shell + [[ -n "$SHELL" ]] && exec ${SHELL#-} || exec zsh } From fbbe902c38549dae8c8e997daeebcc797103ab7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 2 Nov 2016 10:16:59 +0100 Subject: [PATCH 4/4] zsh_reload: add README --- plugins/zsh_reload/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 plugins/zsh_reload/README.md diff --git a/plugins/zsh_reload/README.md b/plugins/zsh_reload/README.md new file mode 100644 index 00000000..d31a827f --- /dev/null +++ b/plugins/zsh_reload/README.md @@ -0,0 +1,23 @@ +# zsh_reload plugin + +The zsh_reload plugin defines a function to reload the zsh session with +just a few keystrokes. + +To use it, add `zsh_reload` to the plugins array in your zshrc file: + +```zsh +plugins=(... zsh_reload) +``` + +## Usage + +To reload the zsh session, just run `src`: + +```zsh +$ vim ~/.zshrc # enabled a plugin +$ src +re-compiling /home/user/.zshrc.zwc: succeeded +re-compiling /home/user/.oh-my-zsh/cache/zcomp-host.zwc: succeeded + +# you now have a fresh zsh session. happy hacking! +```