From 6f3d3be0ec5a10d2ecfa584b2f33b1d6116d2a74 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse Date: Sat, 2 May 2009 17:13:07 +0200 Subject: [PATCH] add a new -h flag, to set current word from calling function: it avoid parsing command twice, and also allows pre-processing it needed, as in xhost completion --- bash_completion | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bash_completion b/bash_completion index 98f4170e..f5fcba9c 100644 --- a/bash_completion +++ b/bash_completion @@ -2701,6 +2701,7 @@ shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger # Arguments: -a Use aliases # -c Use `:' suffix # -F configfile Use `configfile' for configuration settings +# -h host Complete on given host _known_hosts() { local configfile @@ -2708,18 +2709,23 @@ _known_hosts() local -a kh khd config local IFS=$'\n' - COMPREPLY=() - cur=`_get_cword` - ocur=$cur - local OPTIND=1 - while getopts "acF:" flag "$@"; do + local cur_set=0 + while getopts "acF:h:" flag "$@"; do case $flag in a) aliases='yes' ;; c) suffix=':' ;; F) configfile="$OPTARG" ;; + h) cur="$OPTARG"; cur_set=1 ;; esac done + + COMPREPLY=() + if [ $cur_set = 0 ]; then + cur=`_get_cword` + fi + ocur=$cur + [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@} kh=()