From 09f437a86092e3bc2a7e0958a51e3e585b62ffa2 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sun, 24 Mar 2024 17:38:16 +0100 Subject: [PATCH] zsh:diffcmds: Do not unquote pipes in args list diffcmds echo foo %% cat -- '|' is expected to output `foo | cat` and not `foo`. Fix this by changing the order of the substitution and {,un}quoting. --- .config/zsh/zshrc.d/40-functions.zsh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index cd51724..e59bb03 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -693,10 +693,9 @@ diffcmds() { # Just execute the command without *diff if there is only one argument if (( i + 1 == # )); then - # Quote special characters, replace %% with the only argument and - # unquote pipes in arguments that consist of only the quoted pipe - # character. - eval "${(@)${(q@)${@:1:$((i-1))}//\%\%/${@[$#]}}/#%\\|/|}" + # Quote special characters, unquote standalone pipes and replace %% with + # the only argument + eval "${(@)${(@)${(q@)@:1:$((i-1))}/#%\\|/|}//\%\%/${(q)@[$#]}}" return fi @@ -717,11 +716,11 @@ diffcmds() { cmdline=("$cmd") for arg in "${@:$((i+1))}"; do - # Substitute placeholder, wrap in process substitution and add a layer - # of quotation but unquoting single pipes again. + # Add a layer of quotation but unquoting standalone pipes again, + # substitute placeholder and finally wrap in process substitution cmdline+=( "$ps_sub" - "${(@)${(q@)${@:1:$((i-1))}//\%\%/$arg}/#%\\|/|}" + "${(@)${(@)${(q@)@:1:$((i-1))}/#%\\|/|}//\%\%/${(q)arg}}" ")" ) done