-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion
More file actions
52 lines (48 loc) · 1.53 KB
/
completion
File metadata and controls
52 lines (48 loc) · 1.53 KB
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
50
51
52
#!/usr/bin/env bash
function _sync_py_remove_items {
python3 - $@ <<EndOfPython
import sys
s = sys.argv[1]
for arg in s.split(' '):
arg = arg.strip()
if arg not in sys.argv[2:]:
sys.stdout.write(arg + ' ')
sys.stdout.write('\n')
EndOfPython
}
_sync_py() {
local cur=${COMP_WORDS[COMP_CWORD]}
local opts="-o --oneway -h --help"
local syncfile_list="`cd && ls .sync_*`"
local syncfile=
local target=
for ((i=1; i < $COMP_CWORD; i++)); do
local word=${COMP_WORDS[i]}
if [[ $opts =~ "$word" ]]; then
# This is an option. Remove it from the list of remaining options.
case "$word" in
-o|--oneway)
opts=`_sync_py_remove_items "$opts" -o --oneway`
;;
-h|--help)
opts=`_sync_py_remove_items "$opts" -h --help`
;;
esac
else
# We've found a non-option argument. If we haven't seen a syncfile
# yet, it's that. Otherwise, it's a target directory.
if [[ -z "$syncfile" ]]; then
syncfile="$word"
elif [[ -n "$syncfile" && -z "$target" ]]; then
target="$word"
fi
fi
done
COMPREPLY=( $(compgen -W " $opts" -- "$cur") )
if [[ -z "$syncfile" ]]; then
COMPREPLY+=( $(compgen -W "$syncfile_list" -- "$cur") )
elif [[ -n "$syncfile" && -z "$target" ]]; then
COMPREPLY+=( $(compgen -d -- "$cur") )
fi
}
complete -o filenames -F _sync_py sync.py