From a7c529a93c0d8248c296da9fff5c934ddccaabee Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 6 Jul 2023 15:15:50 +0200 Subject: [PATCH] zsh:diffcmds(): Unquote single pipes This makes it possible to diff command chains. For example: diffcmds git format-patch -1 --stdout HEAD~ '|' \ grep '^%%' '|' \ cut -c2- \ -- - + to see if a commit only reordered lines without modifying them. I am not happy with this solution and would prefer a different form of escaping (e.g. with %). --- .config/zsh/zshrc.d/40-functions.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index b11bb57..e2fb70f 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -672,7 +672,7 @@ diffcmds() { # Just execute the command without *diff if there is only one argument if (( i + 1 == # )); then - eval "${(q@)${@:1:$((i-1))}//\%\%/${@[$#]}}" + eval "${(@)${(q@)${@:1:$((i-1))}//\%\%/${@[$#]}}/#%\\|/|}" return fi @@ -691,10 +691,11 @@ diffcmds() { # NOTE: `=()` is necessary since vimdiff is seeking the file. See zshexpn(1) [[ $cmd = vimdiff ]] && ps_sub='=(' || ps_sub='<(' - # Substitute placeholder and wrap in process substitution + # Substitute placeholder, wrap in process substitution and add a layer + # of quotation but unquoting single pipes again. cmdline=("$cmd") for arg in "${@:$((i+1))}"; do - cmdline+=("$ps_sub" "${(q@)${@:1:$((i-1))}//\%\%/$arg}" ")") + cmdline+=("$ps_sub" "${(@)${(q@)${@:1:$((i-1))}//\%\%/$arg}/#%\\|/|}" ")") done eval "$cmdline[@]" }