dd39d43021f78bf88dff7db43f616866c3596c1f

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #5601 from mcornella/refactor-zsh_reload-plugin

Refactor zsh_reload plugin

Diff

 1diff --git a/plugins/zsh_reload/README.md b/plugins/zsh_reload/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..d31a827fe8a31b64499d524036965f2d9f3a08f6
 4--- /dev/null
 5+++ b/plugins/zsh_reload/README.md
 6@@ -0,0 +1,23 @@
 7+# zsh_reload plugin
 8+
 9+The zsh_reload plugin defines a function to reload the zsh session with
10+just a few keystrokes.
11+
12+To use it, add `zsh_reload` to the plugins array in your zshrc file:
13+
14+```zsh
15+plugins=(... zsh_reload)
16+```
17+
18+## Usage
19+
20+To reload the zsh session, just run `src`:
21+
22+```zsh
23+$ vim ~/.zshrc  # enabled a plugin
24+$ src
25+re-compiling /home/user/.zshrc.zwc: succeeded
26+re-compiling /home/user/.oh-my-zsh/cache/zcomp-host.zwc: succeeded
27+
28+# you now have a fresh zsh session. happy hacking!
29+```
30diff --git a/plugins/zsh_reload/zsh_reload.plugin.zsh b/plugins/zsh_reload/zsh_reload.plugin.zsh
31index cde9ebeca7b66a5f9dcb72d957bc761843b6ccb1..51048ba9d09e0ba26a14963c12af9cab84266f1f 100644
32--- a/plugins/zsh_reload/zsh_reload.plugin.zsh
33+++ b/plugins/zsh_reload/zsh_reload.plugin.zsh
34@@ -1,13 +1,12 @@
35-# reload zshrc
36-function src()
37-{
38-  local cache=$ZSH_CACHE_DIR
39-  autoload -U compinit zrecompile
40-  compinit -d "$cache/zcomp-$HOST"
41+src() {
42+	local cache="$ZSH_CACHE_DIR"
43+	autoload -U compinit zrecompile
44+	compinit -i -d "$cache/zcomp-$HOST"
45 
46-  for f in ~/.zshrc "$cache/zcomp-$HOST"; do
47-    zrecompile -p $f && command rm -f $f.zwc.old
48-  done
49+	for f in ~/.zshrc "$cache/zcomp-$HOST"; do
50+		zrecompile -p $f && command rm -f $f.zwc.old
51+	done
52 
53-  source ~/.zshrc
54+	# Use $SHELL if available; remove leading dash if login shell
55+	[[ -n "$SHELL" ]] && exec ${SHELL#-} || exec zsh
56 }