zsh:diffcmds: Slight refactor & format adjustments

This commit is contained in:
2025-06-20 12:29:19 +02:00
parent f636479b70
commit c27bf72fee

View File

@@ -700,10 +700,10 @@ diffcmds() {
# Quote special characters and split into arrays # Quote special characters and split into arrays
set -- "${(q@)@}" set -- "${(q@)@}"
template=("${@:1:$((i-1))}") template=( "${@:1:$((i-1))}" )
args=("${@:$((i+1))}") args=("${@:$((i+1))}")
# Unquote standalone pipes # Unquote standalone pipes
template=("${(@)template/#%\\|/|}") template=( "${(@)template/#%\\|/|}" )
# Place arguments at the back if no position was supplied with `%%` # Place arguments at the back if no position was supplied with `%%`
[[ "$template[@]" =~ '%%' ]] || template+='%%' [[ "$template[@]" =~ '%%' ]] || template+='%%'
@@ -727,16 +727,12 @@ diffcmds() {
fi fi
# NOTE: `=()` is necessary since vimdiff is seeking the file. See zshexpn(1) # NOTE: `=()` is necessary since vimdiff is seeking the file. See zshexpn(1)
[[ $diff_cmd = vimdiff ]] && ps_sub='=(' || ps_sub='<(' [[ $diff_cmd = vimdiff ]] && ps_sub='=' || ps_sub='<'
final_cmd=("$diff_cmd") final_cmd=("$diff_cmd")
for arg in "$args[@]"; do for arg in "$args[@]"; do
# Substitute placeholder and wrap in process substitution # Substitute placeholder and wrap in process substitution
final_cmd+=( final_cmd+=( "$ps_sub(${(@)template//\%\%/$arg})" )
"$ps_sub"
"${(@)template//\%\%/$arg}"
")"
)
done done
eval "$final_cmd[@]" eval "$final_cmd[@]"
} }