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[
#
# $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>
#
@ -381,10 +381,11 @@ complete -F _killall killall
#
_find()
{
local cur prev i
local cur ncur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]#-}
cur=${COMP_WORDS[COMP_CWORD]#}
ncur=${cur#-}
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
@ -393,34 +394,34 @@ _find()
return 0
;;
-?(a)newer|-fls|-fprint?(0|f))
COMPREPLY=( $( compgen -f $cur ) )
COMPREPLY=( $( compgen -f $ncur ) )
return 0
;;
-fstype)
# 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
;;
-gid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$cur'/) print $3}' /etc/group ) )
{if ($3 ~ /^'$ncur'/) print $3}' /etc/group ) )
return 0
;;
-group)
COMPREPLY=( $( compgen -g $cur ) )
COMPREPLY=( $( compgen -g $ncur ) )
return 0
;;
-?(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
;;
-uid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$cur'/) print $3}' /etc/passwd ) )
{if ($3 ~ /^'$ncur'/) print $3}' /etc/passwd ) )
return 0
;;
-user)
COMPREPLY=( $( compgen -u $cur ) )
COMPREPLY=( $( compgen -u $ncur ) )
return 0
;;
-[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
@ -432,7 +433,13 @@ _find()
_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
# the dash is an option to itself)
COMPREPLY=( $( compgen -W 'daystart depth follow help maxdepth \
@ -441,7 +448,7 @@ _find()
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 ) )
print print0 printf prune ls' $ncur ) )
# this removes any options from the list of completions that have
# already been specified somewhere on the command line.