2010-06-09 22:33:25 +03:00
|
|
|
# Completions for various core utilities
|
|
|
|
|
|
|
|
# chown(1) completion
|
|
|
|
#
|
|
|
|
have chown &&
|
|
|
|
_chown()
|
|
|
|
{
|
2011-05-01 22:18:40 +03:00
|
|
|
local cur prev words cword split
|
2011-04-20 14:42:30 +03:00
|
|
|
# Don't treat user:group as separate words.
|
2011-05-01 22:18:40 +03:00
|
|
|
_init_completion -s -n : || return
|
2010-06-09 22:33:25 +03:00
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
--from)
|
|
|
|
_usergroup
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--reference)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
|
|
# Complete -options
|
|
|
|
local w opts
|
2011-04-20 14:42:30 +03:00
|
|
|
for w in "${words[@]}" ; do
|
2010-06-09 22:33:25 +03:00
|
|
|
[[ "$w" == -@(R|-recursive) ]] && opts="-H -L -P" && break
|
|
|
|
done
|
|
|
|
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
|
|
|
|
--no-dereference --from --silent --quiet --reference --recursive \
|
|
|
|
--verbose --help --version $opts' -- "$cur" ) )
|
|
|
|
else
|
|
|
|
local args
|
|
|
|
|
|
|
|
# The first argument is an usergroup; the rest are filedir.
|
|
|
|
_count_args :
|
|
|
|
|
2011-02-10 23:55:16 +02:00
|
|
|
if [[ $args -eq 1 ]]; then
|
2010-10-31 21:23:26 +02:00
|
|
|
_usergroup -u
|
2010-06-09 22:33:25 +03:00
|
|
|
else
|
|
|
|
_filedir
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
} &&
|
2010-11-01 19:26:53 +02:00
|
|
|
complete -F _chown chown
|
2010-06-09 22:33:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
# chgrp(1) completion
|
|
|
|
#
|
|
|
|
have chgrp &&
|
|
|
|
_chgrp()
|
|
|
|
{
|
2011-05-01 22:18:40 +03:00
|
|
|
local cur prev words cword split
|
|
|
|
_init_completion -s || return
|
2010-06-09 22:33:25 +03:00
|
|
|
|
|
|
|
cur=${cur//\\\\/}
|
|
|
|
|
|
|
|
if [[ "$prev" == --reference ]]; then
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
# options completion
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
|
|
local w opts
|
2011-04-20 14:42:30 +03:00
|
|
|
for w in "${words[@]}" ; do
|
2010-06-09 22:33:25 +03:00
|
|
|
[[ "$w" == -@(R|-recursive) ]] && opts="-H -L -P" && break
|
|
|
|
done
|
|
|
|
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
|
|
|
|
--no-dereference --silent --quiet --reference --recursive \
|
|
|
|
--verbose --help --version $opts' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# first parameter on line or first since an option?
|
2011-04-20 14:42:30 +03:00
|
|
|
if [[ $cword -eq 1 && "$cur" != -* || "$prev" == -* ]]; then
|
2011-03-27 12:40:44 +02:00
|
|
|
_allowed_groups "$cur"
|
2010-06-09 22:33:25 +03:00
|
|
|
else
|
|
|
|
_filedir || return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
} &&
|
2010-11-01 19:26:53 +02:00
|
|
|
complete -F _chgrp chgrp
|
2010-06-09 22:33:25 +03:00
|
|
|
|
|
|
|
# id(1) completion
|
|
|
|
#
|
|
|
|
have id &&
|
|
|
|
_id()
|
|
|
|
{
|
2011-04-20 14:42:30 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion || return
|
2010-06-09 22:33:25 +03:00
|
|
|
|
|
|
|
if [[ "$cur" == -* ]]; then
|
2011-04-28 21:21:31 +03:00
|
|
|
local opts=$( _parse_help "$1" )
|
|
|
|
[[ $opts ]] || opts="-G -g -u" # POSIX fallback
|
|
|
|
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
|
2010-06-09 22:33:25 +03:00
|
|
|
else
|
|
|
|
COMPREPLY=( $( compgen -u "$cur" ) )
|
|
|
|
fi
|
|
|
|
} &&
|
|
|
|
complete -F _id id
|
|
|
|
|
2011-01-24 00:20:32 +02:00
|
|
|
# mktemp(1) completion
|
|
|
|
#
|
|
|
|
have mktemp &&
|
|
|
|
_mktemp()
|
|
|
|
{
|
2011-05-01 22:18:40 +03:00
|
|
|
local cur prev words cword split
|
|
|
|
_init_completion -s || return
|
2011-01-24 00:20:32 +02:00
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
--help|--version|--suffix)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--tmpdir|-p)
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
$split && return 0
|
|
|
|
|
2011-04-28 21:21:31 +03:00
|
|
|
if [[ "$cur" == -* ]]; then
|
|
|
|
local opts=$( _parse_help "$1" )
|
|
|
|
[[ $opts ]] || opts="-d -u -q -p -t" # non-GNU fallback
|
|
|
|
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
|
2011-05-02 11:41:52 +03:00
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
2011-04-28 21:21:31 +03:00
|
|
|
fi
|
2011-01-24 00:20:32 +02:00
|
|
|
} &&
|
|
|
|
complete -F _mktemp mktemp
|
|
|
|
|
2010-06-09 22:33:25 +03:00
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
|
|
|
# sh-basic-offset: 4
|
|
|
|
# sh-indent-comment: t
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|