diff options
author | Ben Walton <bdwalton@gmail.com> | 2022-08-02 18:28:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-02 19:28:44 +0200 |
commit | 97134d1eed19b72a9c4bf90a2effa847221608bf (patch) | |
tree | c44e00232db1fb4c3a83d05cf04edc8a04243544 /lib/cli.zsh | |
parent | 0346cdf7f63bcddc704cc0551f260d31adb8fc9d (diff) | |
download | zsh-97134d1eed19b72a9c4bf90a2effa847221608bf.tar.gz zsh-97134d1eed19b72a9c4bf90a2effa847221608bf.tar.bz2 zsh-97134d1eed19b72a9c4bf90a2effa847221608bf.zip |
fix(cli): make `omz` honour symlinks when changing `.zshrc` (#11082)
Diffstat (limited to 'lib/cli.zsh')
-rw-r--r-- | lib/cli.zsh | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/cli.zsh b/lib/cli.zsh index b71f6d9ce..db659c11f 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -280,9 +280,10 @@ multi == 1 && length(\$0) > 0 { " 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" + local zshrc="${${:-"${zdot}/.zshrc"}:A}" + awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \ + && command cp -f "$zshrc" "$zdot/.zshrc.bck" \ + && command mv -f "$zdot/.zshrc.new" "$zshrc" # Exit if the new .zshrc file wasn't created correctly [[ $? -eq 0 ]] || { @@ -294,8 +295,7 @@ multi == 1 && length(\$0) > 0 { # Exit if the new .zshrc file has syntax errors if ! command 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" + command mv -f "$zdot/.zshrc.bck" "$zshrc" return 1 fi @@ -354,9 +354,10 @@ multi == 1 && /^[^#]*\)/ { " 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" + local zshrc="${${:-"${zdot}/.zshrc"}:A}" + awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \ + && command cp -f "$zshrc" "$zdot/.zshrc.bck" \ + && command mv -f "$zdot/.zshrc.new" "$zshrc" # Exit if the new .zshrc file wasn't created correctly [[ $? -eq 0 ]] || { @@ -368,8 +369,7 @@ multi == 1 && /^[^#]*\)/ { # Exit if the new .zshrc file has syntax errors if ! command 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" + command mv -f "$zdot/.zshrc.bck" "$zshrc" return 1 fi @@ -715,7 +715,8 @@ END { ' local zdot="${ZDOTDIR:-$HOME}" - awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \ + local zshrc="${${:-"${zdot}/.zshrc"}:A}" + awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \ || { # Prepend ZSH_THEME= line to .zshrc if it doesn't exist cat <<EOF @@ -724,8 +725,8 @@ ZSH_THEME="$1" # set by \`omz\` EOF cat "$zdot/.zshrc" } > "$zdot/.zshrc.new" \ - && command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \ - && command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc" + && command cp -f "$zshrc" "$zdot/.zshrc.bck" \ + && command mv -f "$zdot/.zshrc.new" "$zshrc" # Exit if the new .zshrc file wasn't created correctly [[ $? -eq 0 ]] || { @@ -737,8 +738,7 @@ EOF # Exit if the new .zshrc file has syntax errors if ! command 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" + command mv -f "$zdot/.zshrc.bck" "$zshrc" return 1 fi |