-
Notifications
You must be signed in to change notification settings - Fork 157
/
jo.bash
38 lines (32 loc) · 1014 Bytes
/
jo.bash
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
# bash completion for jo(1)
_jo() {
# Don't split words on =, for =@ and =% handling
COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
# No completion if an exit causing flag is around
local i
for i in ${!COMP_WORDS[@]}; do
[[ $i -ne $COMP_CWORD && ${COMP_WORDS[i]} == -*[hvV]* ]] && return 0
done
# Complete available options following a dash
if [[ $2 == -* ]]; then
COMPREPLY=( $(compgen -W '-a -B -h -p -v -V' -- "$2") )
return 0
fi
# Complete filenames on =@ and =%
if [[ $2 == *=[@%]* ]]; then
local file prefix
file="${2#*=[@%]}"
prefix="${2:0:${#2}-${#file}}"
compopt -o filenames
COMPREPLY=( $(compgen -f -- "$file") )
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
if [[ -d "${COMPREPLY[0]}" ]]; then
COMPREPLY[0]+=/
compopt -o nospace
fi
COMPREPLY[0]="$prefix${COMPREPLY[0]}"
fi
return 0
fi
} &&
complete -F _jo jo