be4a952972de03d501fbff79435ae41594f06bac

Author
Monson Shao <holymonson@gmail.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

feat(cli)!: add `omz reload` command and deprecate `zsh_reload` plugin (#9078)

BREAKING CHANGE: the `zsh_reload` plugin is deprecated. Instead of using its `src`
function, use `omz reload` or `exec zsh` to reload zsh after making changes to
your `.zshrc` file.

Closes #9078

Diff

 1diff --git a/lib/cli.zsh b/lib/cli.zsh
 2index cadc82e27e9cbdb2d792bed535b0655ff460243e..773891fce749074e0c92b704cdcbfbe61bcf3ef6 100644
 3--- a/lib/cli.zsh
 4+++ b/lib/cli.zsh
 5@@ -26,6 +26,7 @@ function _omz {
 6     'help:Usage information'
 7     'plugin:Manage plugins'
 8     'pr:Manage Oh My Zsh Pull Requests'
 9+    'reload:Reload the current zsh session'
10     'theme:Manage themes'
11     'update:Update Oh My Zsh'
12   )
13@@ -159,6 +160,7 @@ Available commands:
14   changelog           Print the changelog
15   plugin <command>    Manage plugins
16   pr     <command>    Manage Oh My Zsh Pull Requests
17+  reload              Reload the current zsh session
18   theme  <command>    Manage themes
19   update              Update Oh My Zsh
20 
21@@ -598,6 +600,16 @@ function _omz::pr::test {
22   )
23 }
24 
25+function _omz::reload {
26+  # Delete current completion cache
27+  command rm -f $_comp_dumpfile $ZSH_COMPDUMP
28+
29+  # Old zsh versions don't have ZSH_ARGZERO
30+  local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
31+  # Check whether to run a login shell
32+  [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
33+}
34+
35 function _omz::theme {
36   (( $# > 0 && $+functions[_omz::theme::$1] )) || {
37     cat >&2 <<EOF
38diff --git a/plugins/zsh_reload/README.md b/plugins/zsh_reload/README.md
39index d31a827fe8a31b64499d524036965f2d9f3a08f6..0b2e2a7753ae661edce7a4d4d392c81660820d6c 100644
40--- a/plugins/zsh_reload/README.md
41+++ b/plugins/zsh_reload/README.md
42@@ -1,23 +1,3 @@
43 # zsh_reload plugin
44 
45-The zsh_reload plugin defines a function to reload the zsh session with
46-just a few keystrokes.
47-
48-To use it, add `zsh_reload` to the plugins array in your zshrc file:
49-
50-```zsh
51-plugins=(... zsh_reload)
52-```
53-
54-## Usage
55-
56-To reload the zsh session, just run `src`:
57-
58-```zsh
59-$ vim ~/.zshrc  # enabled a plugin
60-$ src
61-re-compiling /home/user/.zshrc.zwc: succeeded
62-re-compiling /home/user/.oh-my-zsh/cache/zcomp-host.zwc: succeeded
63-
64-# you now have a fresh zsh session. happy hacking!
65-```
66+**This plugin is deprecated.** Use `omz reload` or `exec zsh` instead.
67diff --git a/plugins/zsh_reload/zsh_reload.plugin.zsh b/plugins/zsh_reload/zsh_reload.plugin.zsh
68index 0d29a7ce301780faab403fb93a1abfd5c17578ce..6a058ec5e9804b1159c7bae1299a94c78d4293f1 100644
69--- a/plugins/zsh_reload/zsh_reload.plugin.zsh
70+++ b/plugins/zsh_reload/zsh_reload.plugin.zsh
71@@ -1,22 +1,7 @@
72-src() {
73-	local cache="$ZSH_CACHE_DIR"
74-	autoload -U compinit zrecompile
75-	compinit -i -d "$cache/zcomp-$HOST"
76-
77-	for f in ${ZDOTDIR:-~}/.zshrc "$cache/zcomp-$HOST"; do
78-		zrecompile -p $f && command rm -f $f.zwc.old
79-	done
80+print ${(%):-"%F{yellow}The \`zsh_reload\` plugin is deprecated and will be removed."}
81+print ${(%):-"Use \`%Bomz reload%b\` or \`%Bexec zsh%b\` instead.%f"}
82 
83-	# Use $SHELL if it's available and a zsh shell
84-	local shell="$ZSH_ARGZERO"
85-	if [[ "${${SHELL:t}#-}" = zsh ]]; then
86-		shell="$SHELL"
87-	fi
88-
89-	# Remove leading dash if login shell and run accordingly
90-	if [[ "${shell:0:1}" = "-" ]]; then
91-		exec -l "${shell#-}"
92-	else
93-		exec "$shell"
94-	fi
95+src() {
96+  print ${(%):-"%F{yellow}$0 is deprecated. Use \`%Bomz reload%b\` or \`%Bexec zsh%b\` instead.%f\n"}
97+  omz reload
98 }