- default to _dirnames on _find
- fixed bug in _known_hosts that caused keys to be printed from known_hosts2 files - made _ssh a little more intelligent - added _scp - made _cd expand ~ in directory specs - declared i as a local variable in many functions
This commit is contained in:
parent
4253e056d8
commit
fffa610ef8
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# <![CDATA[
|
# <![CDATA[
|
||||||
#
|
#
|
||||||
# $Id: bash_completion,v 1.26 2001/11/05 00:11:48 ianmacd Exp $
|
# $Id: bash_completion,v 1.27 2001/11/20 05:15:48 ianmacd Exp $
|
||||||
#
|
#
|
||||||
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
||||||
#
|
#
|
||||||
@ -108,7 +108,7 @@ have()
|
|||||||
#
|
#
|
||||||
_chown()
|
_chown()
|
||||||
{
|
{
|
||||||
local cur prev user group
|
local cur prev user group i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -311,7 +311,7 @@ _man()
|
|||||||
#
|
#
|
||||||
_killall()
|
_killall()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -354,7 +354,7 @@ complete -F _killall killall
|
|||||||
#
|
#
|
||||||
_find()
|
_find()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]#-}
|
cur=${COMP_WORDS[COMP_CWORD]#-}
|
||||||
@ -438,7 +438,7 @@ _find()
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
complete -F _find -o filenames find
|
complete -F _find -o dirnames find
|
||||||
|
|
||||||
# Linux ifconfig(8) completion
|
# Linux ifconfig(8) completion
|
||||||
#
|
#
|
||||||
@ -813,7 +813,7 @@ _rpm()
|
|||||||
have apt-get &&
|
have apt-get &&
|
||||||
_apt-get()
|
_apt-get()
|
||||||
{
|
{
|
||||||
local cur prev special
|
local cur prev special i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -861,7 +861,7 @@ _apt-get()
|
|||||||
have apt-cache &&
|
have apt-cache &&
|
||||||
_apt-cache()
|
_apt-cache()
|
||||||
{
|
{
|
||||||
local cur prev special
|
local cur prev special i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -928,7 +928,7 @@ complete -F _chsh chsh
|
|||||||
have chkconfig &&
|
have chkconfig &&
|
||||||
_chkconfig()
|
_chkconfig()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev i
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -973,6 +973,7 @@ _known_hosts()
|
|||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
cur=${cur#*@}
|
||||||
kh=()
|
kh=()
|
||||||
|
|
||||||
[ -r /etc/known_hosts ] && kh[0]=/etc/known_hosts
|
[ -r /etc/known_hosts ] && kh[0]=/etc/known_hosts
|
||||||
@ -996,8 +997,9 @@ _known_hosts()
|
|||||||
cur="^$cur"
|
cur="^$cur"
|
||||||
fi
|
fi
|
||||||
# FS needs to look for a comma separated list
|
# FS needs to look for a comma separated list
|
||||||
COMPREPLY=( $( awk 'BEGIN {FS="[ ,]"}
|
COMPREPLY=( $( awk 'BEGIN {FS=","}
|
||||||
{for (i=1; i<=NR; ++i) { \
|
{for (i=1; i<=2; ++i) { \
|
||||||
|
gsub(" .*$", "", $i); \
|
||||||
if ($i ~ /'$cur'/) {print $i} \
|
if ($i ~ /'$cur'/) {print $i} \
|
||||||
}}' ${kh[@]} ) )
|
}}' ${kh[@]} ) )
|
||||||
else
|
else
|
||||||
@ -1015,7 +1017,7 @@ complete -F _known_hosts traceroute ping fping telnet host nslookup
|
|||||||
have ssh &&
|
have ssh &&
|
||||||
_ssh()
|
_ssh()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev COMPREPLY_SAVE=()
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -1025,27 +1027,38 @@ _ssh()
|
|||||||
-*c)
|
-*c)
|
||||||
COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
|
COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
|
||||||
arcfour cast128-cbc' $cur ) )
|
arcfour cast128-cbc' $cur ) )
|
||||||
return 0
|
|
||||||
;;
|
;;
|
||||||
-*l)
|
-*l)
|
||||||
COMPREPLY=( $( compgen -u $cur ) )
|
COMPREPLY=( $( compgen -u $cur ) )
|
||||||
return 0
|
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY_SAVE=( $( compgen -c $cur ) )
|
||||||
|
_known_hosts
|
||||||
|
COMPREPLY=( ${COMPREPLY[@]} ${COMPREPLY_SAVE[@]} )
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Host has been specified, so now do simple command completion
|
|
||||||
if [ $COMP_CWORD -gt 1 ]; then
|
|
||||||
COMPREPLY=( $( compgen -c $cur ) )
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Otherwise, check for known hosts
|
|
||||||
_known_hosts
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
[ "$have" ] && complete -F _ssh ssh slogin sftp
|
[ "$have" ] && complete -F _ssh ssh slogin sftp
|
||||||
|
|
||||||
|
have scp &&
|
||||||
|
_scp()
|
||||||
|
{
|
||||||
|
local cur prev COMPREPLY_SAVE=()
|
||||||
|
|
||||||
|
COMPREPLY=()
|
||||||
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
|
|
||||||
|
COMPREPLY_SAVE=( $( compgen -f $cur ) )
|
||||||
|
_known_hosts
|
||||||
|
COMPREPLY=( ${COMPREPLY[@]} ${COMPREPLY_SAVE[@]} )
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
[ "$have" ] && complete -F _scp scp
|
||||||
|
|
||||||
|
|
||||||
# Linux route(8) completion. This could be improved by adding address family
|
# Linux route(8) completion. This could be improved by adding address family
|
||||||
# completion for -A, etc.
|
# completion for -A, etc.
|
||||||
#
|
#
|
||||||
@ -1239,9 +1252,17 @@ _cd()
|
|||||||
{
|
{
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]} dirs=()
|
local cur=${COMP_WORDS[COMP_CWORD]} dirs=()
|
||||||
|
|
||||||
# standard dir completion if parameter contains a /
|
# expand ~username type directory specifications
|
||||||
[[ "$cur" == /* ]] && COMPREPLY=( $( compgen -d $cur ) ) && return 0
|
if [[ "$cur" == \~*/* ]]; then
|
||||||
|
eval cur=$cur
|
||||||
|
elif [[ "$cur" == \~* ]]; then
|
||||||
|
cur=${cur#\~}
|
||||||
|
COMPREPLY=( $( compgen -P '~' -u $cur ) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# standard dir completion if parameter starts with /, ./ or ../
|
||||||
|
[[ "$cur" == ?(.)?(.)/* ]] && COMPREPLY=( $( compgen -d $cur ) ) && return 0
|
||||||
if [ -n "$CDPATH" ]; then
|
if [ -n "$CDPATH" ]; then
|
||||||
# we have a CDPATH, so loop on its contents
|
# we have a CDPATH, so loop on its contents
|
||||||
for i in ${CDPATH//:/ }; do
|
for i in ${CDPATH//:/ }; do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user