2009-05-21 01:40:30 +02:00
|
|
|
# bash completion for GNU find. This makes heavy use of ksh style extended
|
|
|
|
# globs and contains Linux specific code for completing the parameter
|
|
|
|
# to the -fstype option.
|
|
|
|
|
2009-06-08 21:22:43 +03:00
|
|
|
have find &&
|
2009-05-21 01:40:30 +02:00
|
|
|
_find()
|
|
|
|
{
|
2009-10-04 19:42:50 +02:00
|
|
|
local cur prev i exprfound onlyonce
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=()
|
|
|
|
cur=`_get_cword`
|
|
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
case "$prev" in
|
2009-11-22 11:43:26 +01:00
|
|
|
-maxdepth|-mindepth)
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
-newer|-anewer|-cnewer|-fls|-fprint|-fprint0|-fprintf|-name|-iname| \
|
|
|
|
-lname|-ilname|-wholename|-iwholename)
|
2009-10-04 19:42:50 +02:00
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-fstype)
|
|
|
|
# this is highly non-portable
|
|
|
|
[ -e /proc/filesystems ] &&
|
|
|
|
COMPREPLY=( $( compgen -W "$( cut -d$'\t' -f2 /proc/filesystems )" \
|
|
|
|
-- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-gid)
|
|
|
|
_gids
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-group)
|
2009-10-22 11:15:27 +03:00
|
|
|
COMPREPLY=( $( compgen -g -- "$cur" 2>/dev/null) )
|
2009-10-04 19:42:50 +02:00
|
|
|
return 0
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
-xtype|-type)
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $( compgen -W 'b c d p f l s' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-uid)
|
|
|
|
_uids
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-user)
|
|
|
|
COMPREPLY=( $( compgen -u -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-exec|-ok)
|
|
|
|
COMP_WORDS=(COMP_WORDS[0] "$cur")
|
|
|
|
COMP_CWORD=1
|
|
|
|
_command
|
|
|
|
return 0
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
-[acm]min|-[acm]time|-iname|-lname|-wholename|-iwholename|-lwholename| \
|
|
|
|
-ilwholename|-inum|-path|-ipath|-regex|-iregex|-links|-perm|-size| \
|
|
|
|
-used|-printf)
|
2009-10-04 19:42:50 +02:00
|
|
|
# do nothing, just wait for a parameter to be given
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
_expand || return 0
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# set exprfound to 1 if there is already an expression present
|
|
|
|
for i in ${COMP_WORDS[@]}; do
|
|
|
|
[[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
|
|
|
|
done
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# handle case where first parameter is not a dash option
|
2009-11-23 20:08:52 +02:00
|
|
|
if [[ "$exprfound" != 1 && "$cur" != [-\(\),\!]* ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
fi
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# complete using basic options
|
|
|
|
COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \
|
|
|
|
-mindepth -mount -noleaf -version -xdev -amin -anewer \
|
|
|
|
-atime -cmin -cnewer -ctime -empty -false -fstype \
|
|
|
|
-gid -group -ilname -iname -inum -ipath -iregex \
|
|
|
|
-wholename \
|
|
|
|
-links -lname -mmin -mtime -name -newer -nouser \
|
|
|
|
-nogroup -perm -regex -size -true -type -uid -used \
|
|
|
|
-user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \
|
|
|
|
-print -print0 -printf -prune -ls -wholename -iwholename' -- "$cur" ) )
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# this removes any options from the list of completions that have
|
|
|
|
# already been specified somewhere on the command line, as long as
|
|
|
|
# these options can only be used once (in a word, "options", in
|
|
|
|
# opposition to "tests" and "actions", as in the find(1) manpage).
|
|
|
|
onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \
|
|
|
|
-noleaf -version -xdev '
|
2009-12-09 22:46:09 +02:00
|
|
|
COMPREPLY=( $( \
|
2009-10-04 19:42:50 +02:00
|
|
|
(while read -d ' ' i; do
|
2009-11-23 20:08:52 +02:00
|
|
|
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
|
2009-10-04 19:42:50 +02:00
|
|
|
continue
|
|
|
|
# flatten array with spaces on either side,
|
|
|
|
# otherwise we cannot grep on word boundaries of
|
|
|
|
# first and last word
|
|
|
|
COMPREPLY=" ${COMPREPLY[@]} "
|
|
|
|
# remove word from list of completions
|
|
|
|
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
|
|
|
|
done
|
2009-12-09 22:46:09 +02:00
|
|
|
echo "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
|
2009-10-04 19:42:50 +02:00
|
|
|
) )
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
_filedir
|
2009-05-21 01:40:30 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
return 0
|
2009-06-08 21:22:43 +03:00
|
|
|
} &&
|
2009-10-22 12:04:29 +03:00
|
|
|
complete -F _find -o filenames find
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
2009-10-04 19:42:50 +02:00
|
|
|
# sh-basic-offset: 4
|
2009-10-01 20:54:51 +03:00
|
|
|
# sh-indent-comment: t
|
2009-10-04 19:42:50 +02:00
|
|
|
# indent-tabs-mode: nil
|
2009-10-01 20:54:51 +03:00
|
|
|
# End:
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|