blob: 6c274567e204fc9f021b06d1a37e407e702b28dc (
plain) (
blame)
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
|
#!/usr/bin/env bash
_conf()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local commands="add ls list search edit cat relink grep help version"
if [[ $COMP_CWORD -gt 1 ]]; then
local lastarg="${COMP_WORDS[$COMP_CWORD-1]}"
case "${COMP_WORDS[1]}" in
l|ls|list)
if [[ $lastarg == "-g" ]]; then
COMPREPLY=($(compgen -W "$(conf ls -G)" -- ${cur}))
else
COMPREPLY=($(compgen -W "$(conf ls -h 2>&1 | awk -F' ' '{print $1}')" -- ${cur}))
fi
;;
add|a)
if [[ $lastarg == "-g" ]]; then
COMPREPLY=($(compgen -W "$(conf ls -G)" -- ${cur}))
else
COMPREPLY=($(compgen -f -- ${cur}))
fi
;;
edit|e|editg|eg|cat|c)
COMPREPLY=($(compgen -W "$(conf ls -G) \
$(conf ls -l | xargs -If basename f) \
$(for g in $(conf ls -G); do \
conf ls -g $g | xargs -If basename f | sed -e "s#^#${g}/#"; \
done)" -- ${cur}))
;;
relink)
COMPREPLY=($(compgen -W "-t --test $(conf ls -G)" -- ${cur}))
;;
esac
else
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
fi
}
complete -F _conf conf
|