From 45253db95f05baf810c117a555ddec60c0349177 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 17 May 2013 13:47:00 +0200 Subject: hostinfo: basepath for the hostinfo files is configurable now The basepath for the hostinfo files could now customized via the HOSTINFO_FILES environment variable or the --path, -p command line option. If nothing exists the default path /usr/local/share/hostinfo is used like before. --- contrib/bash-completion | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'contrib') diff --git a/contrib/bash-completion b/contrib/bash-completion index 0c8fb78..1adad22 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -2,19 +2,54 @@ _hostinfo_hosts="$(for file in /usr/local/share/hostinfo/* ; do basename $file | sed 's/.spline.inf.fu-berlin.de//' ; done)" +_get_first_hostinfo_arg() +{ + local i + + arg= + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" != -* ]]; then + arg=${COMP_WORDS[i]} + break + fi + + [[ "${COMP_WORDS[i]}" == "--path" || "${COMP_WORDS[i]}" == "-p" ]] && i=$((i+1)) + done +} + +_get_hostinfo_path() +{ + local i + + path= + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == "--path" || "${COMP_WORDS[i]}" == "-p" ]]; then + path="--path ${COMP_WORDS[i+1]}" + break + fi + done +} + _hostinfo() { local cur prev COMPREPLY=() _get_comp_words_by_ref cur prev - _get_first_arg - if [[ -z "$arg" ]]; then - _completion="$_hostinfo_hosts" + if [[ "$prev" == "-p" || "$prev" == "--path" ]]; then + COMPREPLY=( $( compgen -d -o dirnames -S "/" $cur ) ) + compopt -o nospace else - _completion="$(hostinfo --keys $arg 2>/dev/null)" - fi + _get_first_hostinfo_arg + _get_hostinfo_path + if [[ -z "$arg" ]]; then + _completion="$_hostinfo_hosts" + else + _completion="$(hostinfo $path --keys $arg 2>/dev/null)" + fi - COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help $_completion" -- $cur ) ) + COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help + -p --path $_completion" -- $cur ) ) + fi } complete -F _hostinfo hostinfo -- cgit v1.2.3-1-g7c22