/
yafc
49 lines (42 loc) · 1.4 KB
/
yafc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# bash completion for yafc
_yafc()
{
local cur prev sed_flags opts aliases len_wo_first_and_last word _alias
COMPREPLY=()
cur=`_get_cword`
sed_flags=-nre
opts="-a --anon -d --debug -D --dump-rc -m --mechanism= -n --norc -p \
--noproxy -q --quiet -r --rcfile= -t --trace= -u --noauto -U \
--noalias -v --verbose -w --wait= -W --workdir= -V --version -h --help"
if [[ ${cur} == -* ]]; then
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
if [ "$( uname )" = "Darwin" ]; then
sed_flags=-nEe
fi
if [ -f ~/.yafc/bookmarks ]; then
aliases=( $( sed $sed_flags \
'/machine/ s/.* alias '\''([^'\'']*)'\''/\1/ p' \
~/.yafc/bookmarks ) )
len_wo_first_and_last=$(( ${#COMP_WORDS[@]} - 2 ))
# If alias is already one of the arguments, don't complete the current
# word to one.
for word in "${COMP_WORDS[@]:1:$len_wo_first_and_last}"; do
for _alias in "${aliases[@]}"; do
[[ $_alias == $word ]] && return 0
done
done
COMPREPLY=( $( compgen -W "${aliases[*]}" -- "$cur" ) )
fi
return 0
} &&
complete -F _yafc -o default yafc
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh