summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2021-12-21 17:01:56 +0100
committerMarc Cornellà <hello@mcornella.com>2021-12-21 17:01:56 +0100
commit8ae373130c8da1458323a196505355c710869e38 (patch)
tree70f00de3ce53ed99a0a7353961c4c6cabbd1a63e /lib
parenta1ec96d125ad421bc291563378b96711689cb1b8 (diff)
downloadzsh-8ae373130c8da1458323a196505355c710869e38.tar.gz
zsh-8ae373130c8da1458323a196505355c710869e38.tar.bz2
zsh-8ae373130c8da1458323a196505355c710869e38.zip
fix(cli): respect `ZDOTDIR` in plugin/theme change commands (#10520)
Fixes #10520
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.zsh49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/cli.zsh b/lib/cli.zsh
index 4917bc354..8cf8368e6 100644
--- a/lib/cli.zsh
+++ b/lib/cli.zsh
@@ -276,9 +276,10 @@ multi == 1 && length(\$0) > 0 {
{ print \$0 }
"
- awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
- && command mv -f ~/.zshrc ~/.zshrc.bck \
- && command mv -f ~/.zshrc.new ~/.zshrc
+ local zdot="${ZDOTDIR:-$HOME}"
+ awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
+ && command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
+ && command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
# Exit if the new .zshrc file wasn't created correctly
[[ $? -eq 0 ]] || {
@@ -288,10 +289,10 @@ multi == 1 && length(\$0) > 0 {
}
# Exit if the new .zshrc file has syntax errors
- if ! zsh -n ~/.zshrc; then
- _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
- command mv -f ~/.zshrc ~/.zshrc.new
- command mv -f ~/.zshrc.bck ~/.zshrc
+ if ! zsh -n "$zdot/.zshrc"; then
+ _omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
+ command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
+ command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
return 1
fi
@@ -351,9 +352,10 @@ multi == 1 && /^[^#]*\)/ {
{ print \$0 }
"
- awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
- && command mv -f ~/.zshrc ~/.zshrc.bck \
- && command mv -f ~/.zshrc.new ~/.zshrc
+ local zdot="${ZDOTDIR:-$HOME}"
+ awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
+ && command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
+ && command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
# Exit if the new .zshrc file wasn't created correctly
[[ $? -eq 0 ]] || {
@@ -363,10 +365,10 @@ multi == 1 && /^[^#]*\)/ {
}
# Exit if the new .zshrc file has syntax errors
- if ! zsh -n ~/.zshrc; then
- _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
- command mv -f ~/.zshrc ~/.zshrc.new
- command mv -f ~/.zshrc.bck ~/.zshrc
+ if ! zsh -n "$zdot/.zshrc"; then
+ _omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
+ command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
+ command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
return 1
fi
@@ -698,17 +700,18 @@ END {
}
'
- awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
+ local zdot="${ZDOTDIR:-$HOME}"
+ awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
|| {
# Prepend ZSH_THEME= line to .zshrc if it doesn't exist
cat <<EOF
ZSH_THEME="$1" # set by \`omz\`
EOF
- cat ~/.zshrc
- } > ~/.zshrc.new \
- && command mv -f ~/.zshrc ~/.zshrc.bck \
- && command mv -f ~/.zshrc.new ~/.zshrc
+ cat "$zdot/.zshrc"
+ } > "$zdot/.zshrc.new" \
+ && command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
+ && command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
# Exit if the new .zshrc file wasn't created correctly
[[ $? -eq 0 ]] || {
@@ -718,10 +721,10 @@ EOF
}
# Exit if the new .zshrc file has syntax errors
- if ! zsh -n ~/.zshrc; then
- _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
- command mv -f ~/.zshrc ~/.zshrc.new
- command mv -f ~/.zshrc.bck ~/.zshrc
+ if ! zsh -n "$zdot/.zshrc"; then
+ _omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
+ command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
+ command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
return 1
fi