fix _find() so that if first command line parameter does not begin with -,

directory completion is performed. Previously 'find h<Tab>' would result
  in 'find -help'.
This commit is contained in:
ianmacd 2002-01-30 18:48:45 +00:00
parent 3c1d0b8528
commit d169c1f6d9

View File

@ -2,7 +2,7 @@
# #
# <![CDATA[ # <![CDATA[
# #
# $Id: bash_completion,v 1.77 2002/01/30 05:08:47 ianmacd Exp $ # $Id: bash_completion,v 1.78 2002/01/30 19:48:45 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -381,10 +381,11 @@ complete -F _killall killall
# #
_find() _find()
{ {
local cur prev i local cur ncur 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
@ -393,34 +394,34 @@ _find()
return 0 return 0
;; ;;
-?(a)newer|-fls|-fprint?(0|f)) -?(a)newer|-fls|-fprint?(0|f))
COMPREPLY=( $( compgen -f $cur ) ) COMPREPLY=( $( compgen -f $ncur ) )
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 ^$cur ) ) COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | grep ^$ncur ) )
return 0 return 0
;; ;;
-gid) -gid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \ COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$cur'/) print $3}' /etc/group ) ) {if ($3 ~ /^'$ncur'/) print $3}' /etc/group ) )
return 0 return 0
;; ;;
-group) -group)
COMPREPLY=( $( compgen -g $cur ) ) COMPREPLY=( $( compgen -g $ncur ) )
return 0 return 0
;; ;;
-?(x)type) -?(x)type)
COMPREPLY=( $( compgen -W 'b c d p f l s' $cur ) ) COMPREPLY=( $( compgen -W 'b c d p f l s' $ncur ) )
return 0 return 0
;; ;;
-uid) -uid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \ COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$cur'/) print $3}' /etc/passwd ) ) {if ($3 ~ /^'$ncur'/) print $3}' /etc/passwd ) )
return 0 return 0
;; ;;
-user) -user)
COMPREPLY=( $( compgen -u $cur ) ) COMPREPLY=( $( compgen -u $ncur ) )
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| \
@ -432,7 +433,13 @@ _find()
_expand || return 0 _expand || return 0
# complete using basic options ($cur has had its dash removed here, # handle case where first parameter is not a dash option
if [ $COMP_CWORD = 1 -a "$cur" = "$ncur" ]; 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 # as otherwise compgen will bomb out with an error, since it thinks
# the dash is an option to itself) # the dash is an option to itself)
COMPREPLY=( $( compgen -W 'daystart depth follow help maxdepth \ COMPREPLY=( $( compgen -W 'daystart depth follow help maxdepth \
@ -441,7 +448,7 @@ _find()
iname inum ipath iregex links lname mmin mtime name \ iname inum ipath iregex links lname mmin mtime name \
newer nouser nogroup perm regex size true type uid \ newer nouser nogroup perm regex size true type uid \
used 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.