1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-15 13:34:18 +01:00

49218: run-help filters cmd_args before calling run-help-<command>

This commit is contained in:
Marlon Richert 2021-09-06 13:45:36 -07:00 committed by Bart Schaefer
parent 35c87f0b3b
commit 1508dc7486
9 changed files with 125 additions and 26 deletions

@ -1,5 +1,11 @@
2021-09-06 Bart Schaefer <schaefer@zsh.org>
* Marlon Richert: 49218: Functions/Misc/run-help,
Functions/Misc/run-help-btrfs, Functions/Misc/run-help-git,
Functions/Misc/run-help-ip, Functions/Misc/run-help-p4,
Functions/Misc/run-help-svk, Functions/Misc/run-help-svn:
run-help filters cmd_args before calling run-help-<command>
* unposted (cf. 49202 and 49217): Src/Zle/zle_hist.c: insertlastword
ignores blank/missing history entries when repeating

@ -101,12 +101,15 @@ do
builtin getln cmd_args
builtin print -z "$cmd_args"
cmd_args=( ${(z)cmd_args} )
# Discard environment assignments, etc.
while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]]
do
shift cmd_args || return 1
done
eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
# Discard the command itself & everything before it.
shift $cmd_args[(i)${run_help_orig_cmd:-$1}] cmd_args ||
return
# Discard options, parameter assignments & paths.
cmd_args=( ${cmd_args[@]:#([-+]*|*=*|*/*|\~*)} )
eval "run-help-$1:t ${(@q)cmd_args}"
else
POSIXLY_CORRECT=1 man $@:t
fi

@ -1,7 +1,3 @@
while [[ $# != 0 && $1 == -* ]]; do
shift
done
case $1 in
(b*) man btrfs-balance ;;
(c*) man btrfs-check ;;

@ -1,9 +1 @@
if [ $# -eq 0 ]; then
man git
else
local al
if al=$(git config --get "alias.$1"); then
1=${al%% *}
fi
man git-$1
fi
git help ${1:-git}

@ -14,10 +14,6 @@ if ! man -w ip-address >/dev/null 2>&1; then
return
fi
while [[ $# != 0 && $1 == -* ]]; do
shift
done
case $1 in
(addrl*) man ip-addrlabel ;;
(a*) man ip-address ;;

@ -2,4 +2,4 @@ if (( ! $# )); then
p4 help commands
else
p4 help $1
fi | ${=PAGER:-less}
fi | ${=PAGER:-more}

@ -1 +1 @@
svk help ${${@:#-*}[1]} | ${=PAGER:-more}
svk help $1 | ${=PAGER:-more}

@ -1 +1 @@
svn help ${${@:#-*}[1]} | ${=PAGER:-more}
svn help $1 | ${=PAGER:-more}

106
Test/Z03run-help.ztst Normal file

@ -0,0 +1,106 @@
%prep
PAGER=cat
unalias run-help
autoload +X -Uz $PWD/../Functions/Misc/run-help*
builtin() {
case "$1 $2" in
( 'getln cmd_args' )
cmd_args="$BUFFER_STACK"
;;
( 'print -z' )
;;
( 'whence -va' )
print -l "$3 is WHENCE:{$3}"
;;
( * )
eval $@
;;
esac
}
man() {
[[ $1 == -w && -n $NO_SUBCMD_MANUALS ]] &&
return 1
print "MAN:{${(qq)@}}"
}
git svn () {
print "${(U)0}:{${(qq)@}}"
}
%test
BUFFER_STACK='btrfs --help'
run-help btrfs
0:btrfs with option flag, no subcmd
>btrfs is WHENCE:{btrfs}
>MAN:{'btrfs'}
BUFFER_STACK='btrfs subvolume snapshot r /btrfs/SV1 /btrfs/SV1-rosnap'
run-help btrfs
0:btrfs with subcmd
>btrfs is WHENCE:{btrfs}
>MAN:{'btrfs-subvolume'}
BUFFER_STACK="sudo $BUFFER_STACK"
run-help btrfs
0:sudo btrfs with subcmd
>btrfs is WHENCE:{btrfs}
>MAN:{'btrfs-subvolume'}
BUFFER_STACK='ip addr add 192.168.50.5 dev eth1'
run-help ip
0:ip with subcmd
>ip is WHENCE:{ip}
>MAN:{'ip-address'}
NO_SUBCMD_MANUALS=1
run-help ip
unset NO_SUBCMD_MANUALS
0:ip with subcmd, but no subcmd manuals
>ip is WHENCE:{ip}
>MAN:{'ip'}
BUFFER_STACK='ip -s -s link ls up'
run-help ip
0:ip with options and subcmd
>ip is WHENCE:{ip}
>MAN:{'ip-link'}
BUFFER_STACK="sudo $BUFFER_STACK"
run-help ip
0:sudo ip with options and subcmd
>ip is WHENCE:{ip}
>MAN:{'ip-link'}
BUFFER_STACK='svn -vq'
run-help svn
0:svn with options
>svn is WHENCE:{svn}
>SVN:{'help'}
BUFFER_STACK+=' commit -m "log messages"'
run-help svn
0:svn with options and subcmd
>svn is WHENCE:{svn}
>SVN:{'help' 'commit'}
BUFFER_STACK='git --exec-path'
run-help git
0:git with option
>git is WHENCE:{git}
>GIT:{'help' 'git'}
BUFFER_STACK='git -C $PWD/.. difftool --no-prompt --tool opendiff --dir-diff'
run-help git
0:git with option, file & subcmd
>git is WHENCE:{git}
>GIT:{'help' 'difftool'}
BUFFER_STACK='git -c http.proxy=someproxy clone https://github.com/user/repo.git'
run-help git
0:git with option, assignment & subcmd
>git is WHENCE:{git}
>GIT:{'help' 'clone'}
%clean