0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00

fix(cli): respect ZDOTDIR in plugin/theme change commands (#10520)

Fixes #10520
This commit is contained in:
Marc Cornellà 2021-12-21 17:01:56 +01:00
parent a1ec96d125
commit 8ae373130c
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -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