add group completion for chgrp

change embedded tabs in the file to $'\t' syntax
be a bit more elegant in determining location of showmount in _mount()
condense awk|grep combo in _configure() to a single sed command
be more intelligent about parsing for exclusion (-X) compspecs when
  binding commands to _file_and_dir()
This commit is contained in:
ianmacd 2002-01-03 00:16:41 +00:00
parent 15dbef4c03
commit 450ab1e5e3

View File

@ -2,7 +2,7 @@
# #
# <![CDATA[ # <![CDATA[
# #
# $Id: bash_completion,v 1.40 2001/12/21 08:56:18 ianmacd Exp $ # $Id: bash_completion,v 1.41 2002/01/03 01:16:41 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -20,6 +20,7 @@
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
[ -n "$DEBUG" ] && set -v
# Set a couple of useful vars # Set a couple of useful vars
# #
OS=$( uname -s ) OS=$( uname -s )
@ -32,7 +33,7 @@ shopt -s extglob progcomp
# completion examples provided with the bash 2.04 source distribution # completion examples provided with the bash 2.04 source distribution
# Make directory commands see only directories # Make directory commands see only directories
complete -d cd mkdir rmdir pushd complete -d mkdir rmdir pushd
# Make file commands see only files # Make file commands see only files
complete -f cat less more ln strip complete -f cat less more ln strip
@ -62,7 +63,7 @@ complete -A signal -P '-' kill
complete -u finger su usermod userdel passwd complete -u finger su usermod userdel passwd
# group commands see only groups # group commands see only groups
complete -g groupmod groupdel passwd complete -g groupmod groupdel passwd chgrp
# bg completes with stopped jobs # bg completes with stopped jobs
complete -A stopped -P '%' bg complete -A stopped -P '%' bg
@ -169,12 +170,11 @@ complete -F _umount -o filenames umount
# #
_mount() _mount()
{ local cur sm { local cur i sm
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
[ -x /sbin/showmount ] && sm=/sbin/showmount for i in {,/usr}/sbin/showmount; do [ -x $i ] && sm=$i && break; done
[ -x /usr/sbin/showmount ] && sm=/usr/sbin/showmount
if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
COMPREPLY=( $( $sm -e --no-headers ${cur%%:*} | \ COMPREPLY=( $( $sm -e --no-headers ${cur%%:*} | \
@ -363,8 +363,8 @@ _find()
return 0 return 0
;; ;;
-fstype) -fstype)
# this is highly non-portable (the option to -d is a tab) # this is highly non-portable
COMPREPLY=( $( cut -d' ' -f 2 /proc/filesystems | grep ^$cur ) ) COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | grep ^$cur ) )
return 0 return 0
;; ;;
-gid) -gid)
@ -630,8 +630,8 @@ _rpm()
return 0 return 0
;; ;;
--eval) --eval)
# get a list of macros (char class contains a space and tab) # get a list of macros
COMPREPLY=( $( sed -ne 's/^\(%'${cur#\%}'[^ ]*\).*$/\1/p' \ COMPREPLY=( $( sed -ne 's/^\(%'${cur#\%}'[^ '$'\t'']*\).*$/\1/p' \
/usr/lib/rpm/macros ) ) /usr/lib/rpm/macros ) )
return 0 return 0
;; ;;
@ -1216,7 +1216,7 @@ _iptables()
} }
[ "$have" ] && complete -F _iptables iptables [ "$have" ] && complete -F _iptables iptables
# Linux iptables(8) completion # tcpdump(8) completion
# #
have tcpdump && have tcpdump &&
_tcpdump() _tcpdump()
@ -1419,7 +1419,7 @@ _configure_func ()
*) cmd="$1" ;; *) cmd="$1" ;;
esac esac
COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) ) COMPREPLY=( $( "$cmd" --help | sed -ne 's/^ *\('$2'[^ '$'\t'',[]\+\).*$/\1/p' ) )
} }
complete -F _configure_func configure complete -F _configure_func configure
@ -1453,9 +1453,11 @@ list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \
) )
) ) ) )
# remove previous compspecs # remove previous compspecs
if [ ${#list[@]} -gt 0 ]; then
eval complete -r ${list[@]} eval complete -r ${list[@]}
# install new compspecs # install new compspecs
eval complete -F _file_and_dir -o filenames ${list[@]} eval complete -F _file_and_dir -o filenames ${list[@]}
fi
unset list[@] unset list[@]
# source user completion file # source user completion file