PageRenderTime 81ms CodeModel.GetById 60ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

/bash_completion_lib/include/comp_install

http://github.com/brinkman83/bashrc
#! | 34 lines | 31 code | 3 blank | 0 comment | 0 complexity | fe4090e6d582d61ff91d0f9d9c2a1f77 MD5 | raw file
 1# Install real completion
 2# See also: _comp_install()
 3# @param $* string  (optional) Arguments to use for completion.  Default is "-F _${BASH_ARGV[0]}"
 4comp_install() {
 5    # Do not install when COMP_INSTALL equals 0
 6    if [ "${COMP_INSTALL:-1}" -ne 0 ]; then
 7	local comp=${BASH_ARGV[0]##*/}  # ${..##*/}: strip up to and including last slash
 8	local dir="${BASH_ARGV[0]%/$comp}"  # Extract dir from completion
 9
10	_comp_install $comp "$dir" "$*"
11    fi
12} # comp_install()
13
14
15# Install real completion
16# NOTE: The default function of the original bash_completion is "_$command".
17#       A less collision-prone default might be "_comp_$command", e.g.
18#       `_comp_ssh' instead of `_ssh' -- FVu, Sat Apr  5 09:21:21 CEST 2008
19# @param $1 string comp
20# @param $2 string dir
21# @param $* string  (optional) Arguments to use for completion.  Default is "-F _${BASH_ARGV[0]}"
22_comp_install() {
23    local comp=$1
24    shift
25    local dir="$1"
26    shift
27        # Don't install completion if 'comp_dir2args()' returns false
28    if comp_dir2args "$dir"; then
29        eval complete ${*:--F _$comp} $COMP_ARGS ${COMP_WORDS[0]}
30    else
31        complete -r $comp
32    fi
33    unset -v COMP_ARGS
34} # _comp_install()