[Bash-completion-commits] ./current r1199: Added support for `-F configfile' to _known_hosts(), ssh, scp and
David Paleino
d.paleino at gmail.com
Sat Nov 1 11:25:38 UTC 2008
------------------------------------------------------------
revno: 1199
committer: David Paleino <d.paleino at gmail.com>
branch nick: current
timestamp: Sat 2008-11-01 12:25:38 +0100
message:
Added support for `-F configfile' to _known_hosts(), ssh, scp and
sftp, thanks to Freddy Vulto (Closes: #504141)
modified:
bash_completion
contrib/ssh
debian/changelog
-------------- next part --------------
=== modified file 'bash_completion'
--- a/bash_completion 2008-11-01 08:49:57 +0000
+++ b/bash_completion 2008-11-01 11:25:38 +0000
@@ -2519,27 +2519,43 @@
# This function performs host completion based on ssh's known_hosts files,
# defaulting to standard host completion if they don't exist.
#
+# Arguments: -a Use aliases
+# -c Use `:' suffix
+# -F configfile Use `configfile' for configuration settings
_known_hosts()
{
- local cur curd ocur user suffix aliases global_kh user_kh hosts i host
- local -a kh khd config
+ local configfile
+ local cur curd ocur user suffix aliases global_kh user_kh hosts i host
+ local -a kh khd config
COMPREPLY=()
cur=`_get_cword`
ocur=$cur
- [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes'
- [ "$1" = -c ] || [ "$2" = -c ] && suffix=':'
+ local OPTIND=1
+ while getopts "acF:" flag "$@"; do
+ case $flag in
+ a) aliases='yes' ;;
+ c) suffix=':' ;;
+ F) configfile="$OPTARG" ;;
+ esac
+ done
+
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
kh=()
# ssh config files
- [ -r /etc/ssh/ssh_config ] &&
- config=( "${config[@]}" "/etc/ssh/ssh_config" )
- [ -r "${HOME}/.ssh/config" ] &&
- config=( "${config[@]}" "${HOME}/.ssh/config" )
- [ -r "${HOME}/.ssh2/config" ] &&
- config=( "${config[@]}" "${HOME}/.ssh2/config" )
+ if [ -n "$configfile" ]; then
+ [ -r "$configfile" ] &&
+ config=( "${config[@]}" "$configfile" )
+ else
+ [ -r /etc/ssh/ssh_config ] &&
+ config=( "${config[@]}" "/etc/ssh/ssh_config" )
+ [ -r "${HOME}/.ssh/config" ] &&
+ config=( "${config[@]}" "${HOME}/.ssh/config" )
+ [ -r "${HOME}/.ssh2/config" ] &&
+ config=( "${config[@]}" "${HOME}/.ssh2/config" )
+ fi
if [ ${#config[@]} -gt 0 ]; then
# expand path (if present) to global known hosts file
@@ -2551,29 +2567,33 @@
# Global known_hosts files
[ -r "$global_kh" ] &&
kh=( "${kh[@]}" "$global_kh" )
- [ -r /etc/ssh/ssh_known_hosts ] &&
- kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
- [ -r /etc/ssh/ssh_known_hosts2 ] &&
- kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 )
- [ -r /etc/known_hosts ] &&
- kh=( "${kh[@]}" /etc/known_hosts )
- [ -r /etc/known_hosts2 ] &&
- kh=( "${kh[@]}" /etc/known_hosts2 )
- [ -d /etc/ssh2/knownhosts ] &&
- khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub )
+ if [ -z "$configfile" ]; then
+ [ -r /etc/ssh/ssh_known_hosts ] &&
+ kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
+ [ -r /etc/ssh/ssh_known_hosts2 ] &&
+ kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 )
+ [ -r /etc/known_hosts ] &&
+ kh=( "${kh[@]}" /etc/known_hosts )
+ [ -r /etc/known_hosts2 ] &&
+ kh=( "${kh[@]}" /etc/known_hosts2 )
+ [ -d /etc/ssh2/knownhosts ] &&
+ khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub )
+ fi
# User known_hosts files
[ -r "$user_kh" ] &&
kh=( "${kh[@]}" "$user_kh" )
- [ -r ~/.ssh/known_hosts ] &&
- kh=( "${kh[@]}" ~/.ssh/known_hosts )
- [ -r ~/.ssh/known_hosts2 ] &&
- kh=( "${kh[@]}" ~/.ssh/known_hosts2 )
- [ -d ~/.ssh2/hostkeys ] &&
- khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub )
+ if [ -z "$configfile" ]; then
+ [ -r ~/.ssh/known_hosts ] &&
+ kh=( "${kh[@]}" ~/.ssh/known_hosts )
+ [ -r ~/.ssh/known_hosts2 ] &&
+ kh=( "${kh[@]}" ~/.ssh/known_hosts2 )
+ [ -d ~/.ssh2/hostkeys ] &&
+ khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub )
+ fi
# If we have known_hosts files to use
- if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then
+ if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 -o -n "$configfile" ]; then
# Escape slashes and dots in paths for awk
cur=${cur//\//\\\/}
cur=${cur//\./\\\.}
@@ -2629,7 +2649,7 @@
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=$user${COMPREPLY[i]}$suffix
done
- else
+ elif [ -z "$configfile" ]; then
# Just do normal hostname completion
COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
fi
=== modified file 'contrib/ssh'
--- a/contrib/ssh 2008-10-24 17:19:37 +0000
+++ b/contrib/ssh 2008-11-01 11:25:38 +0000
@@ -4,6 +4,7 @@
_ssh()
{
local cur prev
+ local optconfigfile
local -a config
COMPREPLY=()
@@ -11,6 +12,9 @@
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
+ -F)
+ _filedir
+ ;;
-*c)
COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
arcfour cast128-cbc' -- $cur ) )
@@ -22,9 +26,24 @@
COMPREPLY=( $( compgen -u -- $cur ) )
;;
*)
- _known_hosts -a
+ # Search COMP_WORDS for '-F configfile' argument
+ set -- "${COMP_WORDS[@]}"
+ while [ $# -gt 0 ]; do
+ if [ "${1:0:2}" = -F ]; then
+ if [ ${#1} -gt 2 ]; then
+ optconfigfile="$1"
+ else
+ shift
+ optconfigfile="-F$1"
+ fi
+ break
+ fi
+ shift
+ done
+
+ _known_hosts -a $optconfigfile
- [ $COMP_CWORD -eq 1 ] || \
+ [ $COMP_CWORD -eq 1 -o -n "$optconfigfile" ] || \
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
esac
@@ -37,6 +56,7 @@
_scp()
{
local cur userhost path
+ local optconfigfile
COMPREPLY=()
cur=`_get_cword ":"`
@@ -63,8 +83,23 @@
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
fi
+
+ # Search COMP_WORDS for '-F configfile' argument
+ set -- "${COMP_WORDS[@]}"
+ while [ $# -gt 0 ]; do
+ if [ "${1:0:2}" = -F ]; then
+ if [ ${#1} -gt 2 ]; then
+ optconfigfile="$1"
+ else
+ shift
+ optconfigfile="-F$1"
+ fi
+ break
+ fi
+ shift
+ done
- [[ "$cur" == */* ]] || _known_hosts -c -a
+ [[ "$cur" == */* ]] || _known_hosts -c -a $optconfigfile
local IFS=$'\t\n'
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
2>/dev/null | sed \
=== modified file 'debian/changelog'
--- a/debian/changelog 2008-10-24 20:12:09 +0000
+++ b/debian/changelog 2008-11-01 11:25:38 +0000
@@ -32,9 +32,11 @@
* Fixed errors with POSIX enabled (Closes: #502804)
* Fixed dpkg-source wrong exit() with return() (Closes: #)
* Added --schedule-only to aptitude's completion (Closes: #502664)
+ * Added support for `-F configfile' to _known_hosts(), ssh, scp and
+ sftp, thanks to Freddy Vulto (Closes: #504141)
* debian/links fixed (Closes: #494292)
- -- David Paleino <d.paleino at gmail.com> Fri, 24 Oct 2008 22:11:01 +0200
+ -- David Paleino <d.paleino at gmail.com> Sat, 01 Nov 2008 12:24:34 +0100
bash-completion (20080705) unstable; urgency=low
More information about the Bash-completion-commits
mailing list