- _find(): code clean-up and removal of potential compgen errors

This commit is contained in:
ianmacd 2002-02-26 23:29:54 +00:00
parent 54ef11bb25
commit 844c7bb6b2

View File

@ -1,6 +1,6 @@
# bash_completion - some programmable completion functions for bash 2.05a
#
# $Id: bash_completion,v 1.149 2002/02/27 00:13:04 ianmacd Exp $
# $Id: bash_completion,v 1.150 2002/02/27 00:29:54 ianmacd Exp $
#
# Copyright (C) Ian Macdonald <ian@caliban.org>
#
@ -397,25 +397,24 @@ _killall()
#
_find()
{
local cur ncur prev i
local cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]#}
ncur=${cur#-}
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
-@(max|min)depth)
COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' ) )
COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) )
return 0
;;
-?(a)newer|-fls|-fprint?(0|f)|-?(i)?(l)name)
COMPREPLY=( $( compgen -f $ncur ) )
COMPREPLY=( $( compgen -f -- $cur ) )
return 0
;;
-fstype)
# this is highly non-portable
COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | grep ^$ncur ) )
COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | grep ^$cur ) )
return 0
;;
-gid)
@ -424,11 +423,11 @@ _find()
return 0
;;
-group)
COMPREPLY=( $( compgen -g $ncur ) )
COMPREPLY=( $( compgen -g -- $cur ) )
return 0
;;
-?(x)type)
COMPREPLY=( $( compgen -W 'b c d p f l s' $ncur ) )
COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) )
return 0
;;
-uid)
@ -437,7 +436,7 @@ _find()
return 0
;;
-user)
COMPREPLY=( $( compgen -u $ncur ) )
COMPREPLY=( $( compgen -u -- $cur ) )
return 0
;;
-[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
@ -450,26 +449,25 @@ _find()
_expand || return 0
# handle case where first parameter is not a dash option
if [ $COMP_CWORD -eq 1 -a "$cur" = "$ncur" ]; then
if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]]; then
COMPREPLY=( $( compgen -d $cur ) )
return 0
fi
# complete using basic options ($ncur has had its dash removed here,
# as otherwise compgen will bomb out with an error, since it thinks
# the dash is an option to itself)
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 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' $ncur ) )
# 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 \
-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' -- $cur ) )
# this removes any options from the list of completions that have
# already been specified somewhere on the command line.
COMPREPLY=( $( echo "${COMP_WORDS[@]}-" | \
(while read -d '-' i; do
COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[ "$i" == "" ] && continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
@ -481,11 +479,6 @@ _find()
echo ${COMPREPLY[@]})
) )
# put dashes back
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]}
done
return 0
}
complete -F _find -o filenames find