- _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 # 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> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -397,25 +397,24 @@ _killall()
# #
_find() _find()
{ {
local cur ncur prev i local cur prev i
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]#} cur=${COMP_WORDS[COMP_CWORD]}
ncur=${cur#-}
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in case "$prev" in
-@(max|min)depth) -@(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 return 0
;; ;;
-?(a)newer|-fls|-fprint?(0|f)|-?(i)?(l)name) -?(a)newer|-fls|-fprint?(0|f)|-?(i)?(l)name)
COMPREPLY=( $( compgen -f $ncur ) ) COMPREPLY=( $( compgen -f -- $cur ) )
return 0 return 0
;; ;;
-fstype) -fstype)
# this is highly non-portable # 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 return 0
;; ;;
-gid) -gid)
@ -424,11 +423,11 @@ _find()
return 0 return 0
;; ;;
-group) -group)
COMPREPLY=( $( compgen -g $ncur ) ) COMPREPLY=( $( compgen -g -- $cur ) )
return 0 return 0
;; ;;
-?(x)type) -?(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 return 0
;; ;;
-uid) -uid)
@ -437,7 +436,7 @@ _find()
return 0 return 0
;; ;;
-user) -user)
COMPREPLY=( $( compgen -u $ncur ) ) COMPREPLY=( $( compgen -u -- $cur ) )
return 0 return 0
;; ;;
-[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \ -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
@ -450,26 +449,25 @@ _find()
_expand || return 0 _expand || return 0
# handle case where first parameter is not a dash option # 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 ) ) COMPREPLY=( $( compgen -d $cur ) )
return 0 return 0
fi fi
# complete using basic options ($ncur has had its dash removed here, # complete using basic options
# as otherwise compgen will bomb out with an error, since it thinks COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \
# the dash is an option to itself) -mindepth -mount -noleaf -version -xdev -amin -anewer \
COMPREPLY=( $( compgen -W 'daystart depth follow help maxdepth \ -atime -cmin -cnewer -ctime -empty -false -fstype \
mindepth mount noleaf version xdev amin anewer atime \ -gid -group -ilname -iname -inum -ipath -iregex \
cmin cnewer ctime empty false fstype gid group ilname \ -links -lname -mmin -mtime -name -newer -nouser \
iname inum ipath iregex links lname mmin mtime name \ -nogroup -perm -regex -size -true -type -uid -used \
newer nouser nogroup perm regex size true type uid \ -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \
used user xtype exec fls fprint fprint0 fprintf ok \ -print -print0 -printf -prune -ls' -- $cur ) )
print print0 printf prune ls' $ncur ) )
# this removes any options from the list of completions that have # this removes any options from the list of completions that have
# already been specified somewhere on the command line. # already been specified somewhere on the command line.
COMPREPLY=( $( echo "${COMP_WORDS[@]}-" | \ COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
(while read -d '-' i; do (while read -d ' ' i; do
[ "$i" == "" ] && continue [ "$i" == "" ] && continue
# flatten array with spaces on either side, # flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of # otherwise we cannot grep on word boundaries of
@ -481,11 +479,6 @@ _find()
echo ${COMPREPLY[@]}) echo ${COMPREPLY[@]})
) ) ) )
# put dashes back
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]}
done
return 0 return 0
} }
complete -F _find -o filenames find complete -F _find -o filenames find