mirror of git://git.code.sf.net/p/zsh/code
44242: Completion: Use _pick_variant -b to detect builtins
This commit is contained in:
parent
64d1373835
commit
a4f4497207
|
@ -1,3 +1,10 @@
|
|||
2019-04-22 Matthew Martin <phy1729@gmail.com>
|
||||
|
||||
* 44242: Completion/Unix/Command/_chown,
|
||||
Completion/Unix/Command/_ln, Completion/Unix/Command/_mv,
|
||||
Completion/Unix/Command/_rm, Completion/Unix/Command/_rmdir:
|
||||
Use _pick_variant -b to detect builtins.
|
||||
|
||||
2019-04-18 Mikael Magnusson <mikachu@gmail.com>
|
||||
|
||||
* dana: 43288: Src/prompt.c: fix line-broken prompts
|
||||
|
|
|
@ -1,43 +1,68 @@
|
|||
#compdef chown chgrp gchown=chown gchgrp=chgrp zf_chown=chown zf_chgrp=chgrp
|
||||
|
||||
local curcontext="$curcontext" state line expl ret=1
|
||||
local curcontext="$curcontext" state line expl ret=1 variant
|
||||
local suf usr grp req deref pattern arg args
|
||||
|
||||
if _pick_variant gnu=Free\ Soft unix --version; then
|
||||
args=(
|
||||
'(-c --changes -v --verbose)'{-c,--changes}'[report each change made]'
|
||||
'(-c --changes -v --verbose)'{-v,--verbose}'[output info for every file processed]'
|
||||
'(-h --no-dereference)--dereference[dereference symlinks]'
|
||||
'(-h --no-dereference --dereference)'{-h,--no-dereference}'[operate on symlinks themselves]'
|
||||
'(-f --silent --quiet)'{-f,--silent,--quiet}"[don't report errors]"
|
||||
'--preserve-root[fail to operate recursively on /]'
|
||||
'--reference=[copy ownership of specified file]:file:_files'
|
||||
'(-R --recursive)'{-R,--recursive}'[change files and directories recursively]'
|
||||
'(-H -L -P)-L[follow all symlinks]'
|
||||
'(-H -L -P)-H[follow symlinks on the command line]'
|
||||
'(-H -L -P)-P[do not follow symlinks (default)]'
|
||||
'(- : *)--help[display help information]'
|
||||
'(- : *)--version[display version information]'
|
||||
)
|
||||
[[ $service = chown ]] &&
|
||||
args+=( '--from=[restrict changes to files by current ownership]: :->owner' )
|
||||
else
|
||||
args=(
|
||||
"-h[operate on symlinks them self]"
|
||||
'-R[change files and directories recursively]'
|
||||
'(-H -L -P)-L[follow all symlinks]'
|
||||
'(-H -L -P)-H[follow symlinks on the command line]'
|
||||
'(-H -L -P)-P[do not follow symlinks (default)]'
|
||||
)
|
||||
for pattern arg in \
|
||||
'(dragonfly|freebsd)*' "-x[don't traverse file systems]" \
|
||||
'(darwin|dragonfly|(free|net)bsd|solaris)*' "-f[don't report errors]" \
|
||||
'(darwin|dragonfly|(free|net)bsd)*' '-v[output info for every file processed]' \
|
||||
'solaris2.<11->' '-s[owner and/or group are Windows SID strings]'
|
||||
do
|
||||
[[ $OSTYPE = $~pattern ]] && args+=( $arg )
|
||||
done
|
||||
fi
|
||||
_pick_variant -r variant -b zsh gnu=Free\ Soft $OSTYPE --version
|
||||
case "$variant" in
|
||||
gnu)
|
||||
args=(
|
||||
'(-c --changes -v --verbose)'{-c,--changes}'[report each change made]'
|
||||
'(-c --changes -v --verbose)'{-v,--verbose}'[output info for every file processed]'
|
||||
'(-h --no-dereference)--dereference[dereference symlinks]'
|
||||
'(-h --no-dereference --dereference)'{-h,--no-dereference}'[operate on symlinks themselves]'
|
||||
'(-f --silent --quiet)'{-f,--silent,--quiet}"[don't report errors]"
|
||||
'--preserve-root[fail to operate recursively on /]'
|
||||
'--reference=[copy ownership of specified file]:file:_files'
|
||||
'(-R --recursive)'{-R,--recursive}'[change files and directories recursively]'
|
||||
'(-H -L -P)-L[follow all symlinks]'
|
||||
'(-H -L -P)-H[follow symlinks on the command line]'
|
||||
'(-H -L -P)-P[do not follow symlinks (default)]'
|
||||
'(- : *)--help[display help information]'
|
||||
'(- : *)--version[display version information]'
|
||||
)
|
||||
[[ $service = chown ]] &&
|
||||
args+=( '--from=[restrict changes to files by current ownership]: :->owner' )
|
||||
;;
|
||||
*)
|
||||
args=(
|
||||
'-h[operate on symlinks them self]'
|
||||
'-R[change files and directories recursively]'
|
||||
)
|
||||
;|
|
||||
zsh)
|
||||
args+=(
|
||||
'-s[enable paranoid behavior]'
|
||||
)
|
||||
;;
|
||||
*)
|
||||
args+=(
|
||||
'(-H -L -P)-L[follow all symlinks]'
|
||||
'(-H -L -P)-H[follow symlinks on the command line]'
|
||||
'(-H -L -P)-P[do not follow symlinks (default)]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
"-x[don't traverse file systems]"
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|solaris*)
|
||||
args+=(
|
||||
"-f[don't report errors]"
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
'-v[output info for every file processed]'
|
||||
)
|
||||
;|
|
||||
solaris2.<11->)
|
||||
args+=(
|
||||
'-s[owner and/or group are Windows SID strings]'
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
||||
(( $+words[(r)--reference*] )) || args+=( '(--reference)1: :->owner' )
|
||||
_arguments -C -s "$args[@]" '*: :->files' && ret=0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#compdef ln gln zf_ln
|
||||
|
||||
local curcontext="$curcontext" state line ret=1
|
||||
local curcontext="$curcontext" state line ret=1 variant
|
||||
local -A opt_args
|
||||
|
||||
local -a args opts
|
||||
|
@ -9,67 +9,66 @@ args=(
|
|||
'-s[create symbolic links instead of hard links]'
|
||||
)
|
||||
|
||||
local variant
|
||||
_pick_variant -r variant gnu=gnu unix --help
|
||||
if [[ $variant == gnu ]]; then
|
||||
opts=(-S)
|
||||
args=(
|
||||
'(-b --backup)-b[create a backup of each existing destination file]' \
|
||||
'(-b --backup)--backup=[create a backup of each existing destination file]::method:((
|
||||
none\:"never create backups"
|
||||
off\:"never create backups"
|
||||
numbered\:"create numbered backup"
|
||||
t\:"create numbered backup"
|
||||
existing\:"same as numbered if numbered backups exist, otherwise same as simple"
|
||||
nil\:"same as numbered if numbered backups exist, otherwise same as simple"
|
||||
simple\:"always create simple backups"
|
||||
never\:"always create simple backups"))'
|
||||
'(-d -F --directory)'{-d,-F,--directory}'[allow the superuser to attempt to hard link directories]'
|
||||
'(-f --force)'{-f,--force}'[remove existing destination files]'
|
||||
'(-i --interactive)'{-i,--interactive}'[prompt before removing destination files]'
|
||||
'(-L --logical)'{-L,--logical}'[create hard links to symbolic link references]'
|
||||
'(-n --no-dereference)'{-n,--no-dereference}'[treat destination symbolic link to a directory as if it were a normal file]'
|
||||
'(-P --physical)'{-P,--physical}'[create hard links directly to symbolic links]'
|
||||
'(-r --relative)'{-r,--relative}'[create symbolic links relative to link location]'
|
||||
'(-s --symbolic)'{-s,--symbolic}'[create symbolic links instead of hard links]'
|
||||
'(-S --suffix)'{-S,--suffix=}'[override default backup suffix]:suffix'
|
||||
'(-t --target-directory)'{-t,--target-directory=}'[specify directory in which to create the links]: :_directories'
|
||||
'(-T --no-target-directory)'{-T,--no-target-directory}'[treat destination as a normal file]'
|
||||
'(-v --verbose)'{-v,--verbose}'[print name of each linked file]'
|
||||
'--help[display usage information and exit]'
|
||||
'--version[display version information and exit]')
|
||||
elif (( ${+builtins[ln]} )); then
|
||||
args+=(
|
||||
'-d[attempt to hard link directories]'
|
||||
{-h,-n}'[do not dereference destination]'
|
||||
'(-f)-i[prompt before removing destination files]')
|
||||
else
|
||||
case $OSTYPE in
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
{-h,-n}'[do not dereference destination]'
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
'-F[remove existing destination directories]'
|
||||
'(-f)-i[prompt before removing destination files]'
|
||||
'-v[print name of each linked file]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
'(-L)-P[create hard links directly to symbolic links]'
|
||||
'(-P)-L[create hard links to symbolic link references]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
"-w[warn if source of a symbolic link doesn't currently exist]"
|
||||
)
|
||||
_pick_variant -r variant -b zsh gnu=gnu $OSTYPE --help
|
||||
case $variant; in
|
||||
gnu)
|
||||
opts=(-S)
|
||||
args=(
|
||||
'(-b --backup)-b[create a backup of each existing destination file]' \
|
||||
'(-b --backup)--backup=[create a backup of each existing destination file]::method:((
|
||||
none\:"never create backups"
|
||||
off\:"never create backups"
|
||||
numbered\:"create numbered backup"
|
||||
t\:"create numbered backup"
|
||||
existing\:"same as numbered if numbered backups exist, otherwise same as simple"
|
||||
nil\:"same as numbered if numbered backups exist, otherwise same as simple"
|
||||
simple\:"always create simple backups"
|
||||
never\:"always create simple backups"))'
|
||||
'(-d -F --directory)'{-d,-F,--directory}'[allow the superuser to attempt to hard link directories]'
|
||||
'(-f --force)'{-f,--force}'[remove existing destination files]'
|
||||
'(-i --interactive)'{-i,--interactive}'[prompt before removing destination files]'
|
||||
'(-L --logical)'{-L,--logical}'[create hard links to symbolic link references]'
|
||||
'(-n --no-dereference)'{-n,--no-dereference}'[treat destination symbolic link to a directory as if it were a normal file]'
|
||||
'(-P --physical)'{-P,--physical}'[create hard links directly to symbolic links]'
|
||||
'(-r --relative)'{-r,--relative}'[create symbolic links relative to link location]'
|
||||
'(-s --symbolic)'{-s,--symbolic}'[create symbolic links instead of hard links]'
|
||||
'(-S --suffix)'{-S,--suffix=}'[override default backup suffix]:suffix'
|
||||
'(-t --target-directory)'{-t,--target-directory=}'[specify directory in which to create the links]: :_directories'
|
||||
'(-T --no-target-directory)'{-T,--no-target-directory}'[treat destination as a normal file]'
|
||||
'(-v --verbose)'{-v,--verbose}'[print name of each linked file]'
|
||||
'--help[display usage information and exit]'
|
||||
'--version[display version information and exit]')
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
zsh)
|
||||
args+=(
|
||||
'-d[attempt to hard link directories]'
|
||||
{-h,-n}'[do not dereference destination]'
|
||||
'(-f)-i[prompt before removing destination files]')
|
||||
;;
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
{-h,-n}'[do not dereference destination]'
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
'-F[remove existing destination directories]'
|
||||
'(-f)-i[prompt before removing destination files]'
|
||||
'-v[print name of each linked file]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
'(-L)-P[create hard links directly to symbolic links]'
|
||||
'(-P)-L[create hard links to symbolic link references]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
"-w[warn if source of a symbolic link doesn't currently exist]"
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
||||
_arguments -C -s $opts : \
|
||||
$args \
|
||||
|
|
|
@ -1,42 +1,54 @@
|
|||
#compdef mv gmv
|
||||
|
||||
local args
|
||||
if _pick_variant gnu=GNU unix --version; then
|
||||
args=(
|
||||
'(-b --backup -n --no-clobber)--backup=[make a backup of each existing destination file]: : _values "backup type"
|
||||
{none,off}"[never make backups]"
|
||||
{numbered,t}"[make numbered backups]"
|
||||
{existing,nil}"[numbered backups, if they already exist]"
|
||||
{simple,never}"[always make simple backups]"'
|
||||
'(-b --backup -n --no-clobber)-b[make a backup of each existing destination file]'
|
||||
'(-f --force -i --interactive -n --no-clobber)'{-f,--force}"[don't prompt before overwriting]"
|
||||
'(-f --force -i --interactive -n --no-clobber)'{-i,--interactive}'[prompt before overwriting existing file]'
|
||||
'--strip-trailing-slashes[remove any trailing slashes from each source argument]'
|
||||
'(-S --suffix)'{-S+,--suffix=}'[specify the backup suffix]:backup suffix [~]'
|
||||
'(-t --target-directory)'{-t+,--target-directory=}'[move all source arguments into specified directory]:directory:_directories'
|
||||
'(-T --no-target-directory)'{-T,--no-target-directory}'[treat final argument as a normal file]'
|
||||
'(-u --update)'{-u,--update}'[move only when destination file is older or missing]'
|
||||
'(-v --verbose)'{-v,--verbose}'[show file names after they are moved]'
|
||||
'(- *)--help[display usage information]'
|
||||
'(- *)--version[display version information]'
|
||||
)
|
||||
[[ $OSTYPE = linux* ]] && args+=(
|
||||
'(-Z --context)'{-Z,--context}'[set SELinux security context of destination file to default type]'
|
||||
)
|
||||
else
|
||||
local pattern arg
|
||||
args=(
|
||||
"(-i -n)-f[don't prompt before overwriting]"
|
||||
'(-f -n)-i[prompt before overwriting existing file]'
|
||||
)
|
||||
for pattern arg in \
|
||||
'(darwin|dragonfly|freebsd)*' "(-f -i)-n[don't overwrite existing file]" \
|
||||
'(darwin|dragonfly|*bsd)*' '-v[show file names after they are moved]' \
|
||||
'(dragonfly|freebsd)*' "-h[if target is a symlink to a directory, don't follow it]"
|
||||
do
|
||||
[[ $OSTYPE = $~pattern ]] && args+=( $arg )
|
||||
done
|
||||
fi
|
||||
local args variant
|
||||
|
||||
_pick_variant -r variant -b zsh gnu=GNU $OSTYPE --version
|
||||
case $variant; in
|
||||
gnu)
|
||||
args=(
|
||||
'(-b --backup -n --no-clobber)--backup=[make a backup of each existing destination file]: : _values "backup type"
|
||||
{none,off}"[never make backups]"
|
||||
{numbered,t}"[make numbered backups]"
|
||||
{existing,nil}"[numbered backups, if they already exist]"
|
||||
{simple,never}"[always make simple backups]"'
|
||||
'(-b --backup -n --no-clobber)-b[make a backup of each existing destination file]'
|
||||
'(-f --force -i --interactive -n --no-clobber)'{-f,--force}"[don't prompt before overwriting]"
|
||||
'(-f --force -i --interactive -n --no-clobber)'{-i,--interactive}'[prompt before overwriting existing file]'
|
||||
'--strip-trailing-slashes[remove any trailing slashes from each source argument]'
|
||||
'(-S --suffix)'{-S+,--suffix=}'[specify the backup suffix]:backup suffix [~]'
|
||||
'(-t --target-directory)'{-t+,--target-directory=}'[move all source arguments into specified directory]:directory:_directories'
|
||||
'(-T --no-target-directory)'{-T,--no-target-directory}'[treat final argument as a normal file]'
|
||||
'(-u --update)'{-u,--update}'[move only when destination file is older or missing]'
|
||||
'(-v --verbose)'{-v,--verbose}'[show file names after they are moved]'
|
||||
'(- *)--help[display usage information]'
|
||||
'(- *)--version[display version information]'
|
||||
)
|
||||
[[ $OSTYPE = linux* ]] && args+=(
|
||||
'(-Z --context)'{-Z,--context}'[set SELinux security context of destination file to default type]'
|
||||
)
|
||||
;;
|
||||
*)
|
||||
args=(
|
||||
"(-i -n)-f[don't prompt before overwriting]"
|
||||
'(-f -n)-i[prompt before overwriting existing file]'
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*)
|
||||
args+=(
|
||||
"(-f -i)-n[don't overwrite existing file]"
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|*bsd*)
|
||||
args+=(
|
||||
'-v[show file names after they are moved]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
"-h[if target is a symlink to a directory, don't follow it]"
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
||||
_arguments -s -S $args \
|
||||
'*:file:_files'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#compdef rm grm zf_rm
|
||||
|
||||
local variant
|
||||
declare -a opts args
|
||||
args=(
|
||||
'(-f --force)'{-f,--force}'[ignore nonexistent files, never prompt]'
|
||||
|
@ -7,47 +8,58 @@ args=(
|
|||
'(-r -R --recursive)'{-r,-R,--recursive}'[remove directories and their contents recursively]'
|
||||
'*:: :->file'
|
||||
)
|
||||
if _pick_variant gnu=gnu unix --help; then
|
||||
opts+=(-S)
|
||||
args+=(
|
||||
'(-i --interactive)-I[prompt when removing many files]'
|
||||
'(-i -I)--interactive=-[prompt under given condition (defaulting to always)]::when:((once\:"prompt when removing many files"
|
||||
always\:"prompt before every removal"))'
|
||||
'--one-file-system[stay within filesystems of files given as arguments]'
|
||||
'( --preserve-root)--no-preserve-root[do not treat / specially]'
|
||||
'(--no-preserve-root )--preserve-root[do not remove / (default)]'
|
||||
'(-d --dir)'{-d,--dir}'[remove directories as well]'
|
||||
'(-v --verbose)'{-v,--verbose}'[explain what is being done]'
|
||||
'(- *)--help[display help message and exit]'
|
||||
'(- *)--version[output version information and exit]'
|
||||
)
|
||||
else
|
||||
args=(${args:#*)--*\[*})
|
||||
case $OSTYPE in
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
'-d[remove directories as well]'
|
||||
'-P[overwrite files before deleting them]'
|
||||
'-v[explain what is being done]'
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
'-W[attempt to undelete named files]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
"-x[don't cross file systems when removing a hierarchy]"
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
'(-i)-I[prompt when removing many files]'
|
||||
)
|
||||
_pick_variant -r variant -b zsh gnu=gnu $OSTYPE --help
|
||||
case $variant; in
|
||||
gnu)
|
||||
opts+=(-S)
|
||||
args+=(
|
||||
'(-i --interactive)-I[prompt when removing many files]'
|
||||
'(-i -I)--interactive=-[prompt under given condition (defaulting to always)]::when:((once\:"prompt when removing many files"
|
||||
always\:"prompt before every removal"))'
|
||||
'--one-file-system[stay within filesystems of files given as arguments]'
|
||||
'( --preserve-root)--no-preserve-root[do not treat / specially]'
|
||||
'(--no-preserve-root )--preserve-root[do not remove / (default)]'
|
||||
'(-d --dir)'{-d,--dir}'[remove directories as well]'
|
||||
'(-v --verbose)'{-v,--verbose}'[explain what is being done]'
|
||||
'(- *)--help[display help message and exit]'
|
||||
'(- *)--version[output version information and exit]'
|
||||
)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
*)
|
||||
args=(${args:#*)--*\[*})
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|openbsd*|zsh)
|
||||
args+=(
|
||||
'-d[remove directories as well]'
|
||||
)
|
||||
;|
|
||||
zsh)
|
||||
args+=(
|
||||
'-s[enable paranoid behavior]'
|
||||
)
|
||||
;;
|
||||
darwin*|dragonfly*|freebsd*|netbsd*|openbsd*)
|
||||
args+=(
|
||||
'-P[overwrite files before deleting them]'
|
||||
'-v[explain what is being done]'
|
||||
)
|
||||
;|
|
||||
darwin*|dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
'-W[attempt to undelete named files]'
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*|netbsd*)
|
||||
args+=(
|
||||
"-x[don't cross file systems when removing a hierarchy]"
|
||||
)
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=(
|
||||
'(-i)-I[prompt when removing many files]'
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
||||
local curcontext=$curcontext state line ret=1
|
||||
declare -A opt_args
|
||||
|
|
|
@ -1,22 +1,30 @@
|
|||
#compdef rmdir grmdir
|
||||
|
||||
local variant
|
||||
local -a args
|
||||
|
||||
args=(
|
||||
'(-p --parents)'{-p,--parents}'[remove each component of the specified paths]'
|
||||
)
|
||||
|
||||
if _pick_variant gnu=GNU unix --version; then
|
||||
args+=(
|
||||
'--ignore-fail-on-non-empty[ignore failure if directory is non-empty]'
|
||||
'(-v --verbose)'{-v,--verbose}'[be verbose]'
|
||||
)
|
||||
else
|
||||
args=(${args:#*\)--*})
|
||||
if [[ $OSTYPE == (dragonfly|freebsd)* ]]; then
|
||||
_pick_variant -r variant -b zsh gnu=GNU $OSTYPE --version
|
||||
case $variant; in
|
||||
gnu)
|
||||
args+=(
|
||||
'--ignore-fail-on-non-empty[ignore failure if directory is non-empty]'
|
||||
'(-v --verbose)'{-v,--verbose}'[be verbose]'
|
||||
)
|
||||
;;
|
||||
zsh)
|
||||
args=()
|
||||
;;
|
||||
*)
|
||||
args=(${args:#*\)--*})
|
||||
;|
|
||||
dragonfly*|freebsd*)
|
||||
args+=('-v[be verbose]')
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
_arguments -s -S -A '-*' \
|
||||
$args \
|
||||
|
|
Loading…
Reference in New Issue