_pnames: Add -s for producing (possibly) truncated names (RedHat: #744406)

pgrep and pkill actually expect these instead of the full names.
This commit is contained in:
Ville Skyttä 2014-11-10 22:36:49 +02:00
parent 9444a8742e
commit 52d8316c5c
2 changed files with 16 additions and 12 deletions

View File

@ -1051,6 +1051,7 @@ _pgids()
# This function completes on process names. # This function completes on process names.
# AIX and SunOS prefer X/Open, all else should be BSD. # AIX and SunOS prefer X/Open, all else should be BSD.
# @param $1 if -s, don't try to avoid truncated command names
[[ $OSTYPE == *@(solaris|aix)* ]] && [[ $OSTYPE == *@(solaris|aix)* ]] &&
_pnames() _pnames()
{ {
@ -1059,17 +1060,20 @@ _pnames()
} || } ||
_pnames() _pnames()
{ {
# FIXME: completes "[kblockd/0]" to "0". Previously it was completed if [[ "$1" == -s ]]; then
# to "kblockd" which isn't correct either. "kblockd/0" would be COMPREPLY=( $( compgen -X '<defunct>' \
# arguably most correct, but killall from psmisc 22 treats arguments -W '$( command ps axo comm | sed -e 1d )' -- "$cur" ) )
# containing "/" specially unless -r is given so that wouldn't quite else
# work either. Perhaps it'd be best to not complete these to anything # FIXME: completes "[kblockd/0]" to "0". Previously it was completed
# for now. # to "kblockd" which isn't correct either. "kblockd/0" would be
# Not using "ps axo comm" because under some Linux kernels, it # arguably most correct, but killall from psmisc 22 treats arguments
# truncates command names (see e.g. http://bugs.debian.org/497540#19) # containing "/" specially unless -r is given so that wouldn't quite
COMPREPLY=( $( compgen -X '<defunct>' -W '$( command ps axo command= | \ # work either. Perhaps it'd be best to not complete these to anything
sed -e "s/ .*//" -e "s:.*/::" -e "s/:$//" -e "s/^[[(-]//" \ # for now.
-e "s/[])]$//" | sort -u )' -- "$cur" ) ) COMPREPLY=( $( compgen -X '<defunct>' -W '$( command ps axo command= | \
sed -e "s/ .*//" -e "s:.*/::" -e "s/:$//" -e "s/^[[(-]//" \
-e "s/[])]$//" | sort -u )' -- "$cur" ) )
fi
} }
# This function completes on user IDs # This function completes on user IDs

View File

@ -39,7 +39,7 @@ _pgrep()
return return
fi fi
_pnames _pnames -s
} && } &&
complete -F _pgrep pgrep pkill complete -F _pgrep pgrep pkill