From f91a652220d32060e43d3af46dba97d808e31fd0 Mon Sep 17 00:00:00 2001 From: ianmacd <> Date: Tue, 2 Apr 2002 06:17:35 +0000 Subject: [PATCH] - add netstat to list of commands that complete on long options - add renice completion, submitted by Michael G , and rewritten helper functions _pids() and _pgids() --- bash_completion | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/bash_completion b/bash_completion index 97fb913b..b7011f2e 100644 --- a/bash_completion +++ b/bash_completion @@ -1,6 +1,6 @@ # bash_completion - some programmable completion functions for bash 2.05a # -# $Id: bash_completion,v 1.243 2002/04/02 07:27:50 ianmacd Exp $ +# $Id: bash_completion,v 1.244 2002/04/02 08:17:35 ianmacd Exp $ # # Copyright (C) Ian Macdonald # @@ -167,6 +167,20 @@ _expand() fi } +# This function completes on process IDs +# +_pids() +{ + COMPREPLY=( $( compgen -W '$( ps axo pid | sed 1d )' -- $cur ) ) +} + +# This function completes on process group IDs +# +_pgids() +{ + COMPREPLY=( $( compgen -W '$( ps axo pgid | sed 1d )' -- $cur ) ) +} + # start of section containing completion functions for bash built-ins # bash alias completion @@ -449,6 +463,36 @@ _man() } [ $OS = Linux -o $OS = Darwin ] && complete -F _man -o filenames man +# renice(8) completion +# +_renice() +{ + local command cur curopt i + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + command=$1 + + i=0 + # walk back throuh command line and find last option + while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do + curopt=${COMP_WORDS[COMP_CWORD-$i]} + case "$curopt" in + -u) + COMPREPLY=( $( compgen -u -- $cur ) ) + ;; + -g) + _pgids + ;; + -p|$command) + _pids + ;; + esac + i=$(( ++i )) + done +} +complete -F _renice renice + # kill(1) completion # _kill() @@ -2063,7 +2107,7 @@ for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \ touch vdir xargs awk gperf grep gpg grub indent less m4 sed shar date \ env seq su tee uname who texindex cat csplit cut expand fmt fold head \ md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \ - uniq wc units wget rsync ldd bash id info irb mkdir rmdir; do + uniq wc units wget rsync ldd bash id info irb mkdir rmdir netstat; do have $i && complete -F _longopt -o filenames $i done unset i