diff --git a/CHANGES b/CHANGES index b4c8cb4d..1b0328e2 100644 --- a/CHANGES +++ b/CHANGES @@ -24,7 +24,7 @@ bash-completion (2.x) * Apply pine completion to alpine too. * Remove many unnecessary short option completions where long ones exist. * Improve configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer, - mysqladmin, service, and ssh completions. + mysqladmin, service, ssh, and general hostname completions. * Add abook and wtf completion, based on work by Raphaƫl Droz. * Add k3b and lftpget completion. * Don't overwrite other host completions when completing from multiple diff --git a/bash_completion b/bash_completion index 8619676c..9cee4250 100644 --- a/bash_completion +++ b/bash_completion @@ -1223,7 +1223,7 @@ _known_hosts() _known_hosts_real() { local configfile flag prefix - local cur curd awkcur user suffix aliases global_kh user_kh hosts i host + local cur curd awkcur user suffix aliases hosts i host local -a kh khd config local OPTIND=1 @@ -1258,22 +1258,17 @@ _known_hosts_real() if [ ${#config[@]} -gt 0 ]; then local OIFS=$IFS IFS=$'\n' - # expand path (if present) to global known hosts file - global_kh=($( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\1"/p' "${config[@]}" )) - for (( i=0; i < ${#global_kh[@]}; i++ )); do - global_kh[i]=$(echo "${global_kh[i]//\"/}") - done - # expand path (if present) to user known hosts file - user_kh=($( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\1"/p' "${config[@]}" )) - for (( i=0; i < ${#user_kh[@]}; i++ )); do - user_kh[i]=$(echo "${user_kh[i]//\"/}") + local -a tmpkh + # expand paths (if present) to global and user known hosts files + tmpkh=( $( sed -ne 's/^[ \t]*\([Gg][Ll][Oo][Bb][Aa][Ll]\|[Uu][Ss][Ee][Rr]\)[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\2"/p' "${config[@]}" ) ) + for i in "${tmpkh[@]}"; do + i=$( echo "${i//\"/}" ) + [ -r "$i" ] && kh=( "${kh[@]}" "$i" ) done IFS=$OIFS fi # Global known_hosts files - [ -r "$global_kh" ] && - kh=( "${kh[@]}" "${global_kh[@]}" ) if [ -z "$configfile" ]; then [ -r /etc/ssh/ssh_known_hosts ] && kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts ) @@ -1288,8 +1283,6 @@ _known_hosts_real() fi # User known_hosts files - [ -r "$user_kh" ] && - kh=( "${kh[@]}" "${user_kh[@]}" ) if [ -z "$configfile" ]; then [ -r ~/.ssh/known_hosts ] && kh=( "${kh[@]}" ~/.ssh/known_hosts )