-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposeur.bash-completion
More file actions
78 lines (67 loc) · 1.64 KB
/
poseur.bash-completion
File metadata and controls
78 lines (67 loc) · 1.64 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# Indicates there are no completions
__poseur_comp_null() {
COMPREPLY=""
}
__poseur_comp_words_include() {
local i=1
while [[ "$i" -lt "$COMP_CWORD" ]]
do
if [[ "${COMP_WORDS[i]}" = "$1" ]]
then
return
fi
(( i++ ))
done
return 1
}
__poseur_comp() {
# break $1 on space, tab, and newline characters,
# and turn it into a newline separated list of words
local list s sep=$'\n' IFS=$' \t\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
for s in $1
do
__poseur_comp_words_include "$s" && continue
list="$list$s$sep"
done
IFS="$sep"
COMPREPLY=($(compgen -W "$list" -- "$cur"))
}
###########################################################
# Bash Completion for `poseur`
###########################################################
_poseur() {
local cur prev opts cmds
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version --no-archive --dismiss --no-linting"
cmds="--archive-path --encoding --python --linesep --decorator --tabsize"
if [[ ${prev} =~ "--help|--version|--no-archive" ]]
then
__poseur_comp_null
return
elif [[ ${prev} =~ "--archive-path|--encoding|--linesep|--decorator|--tabsize" ]]
then
__poseur_comp_null
return
elif [[ ${prev} =~ "--python" ]]
then
__poseur_comp "3.8"
return
fi
if [[ ${cur} =~ -* ]]
then
__poseur_comp "${opts} ${cmds}"
return
elif [[ ${cur} == * ]]
then
__poseur_comp "$(ls *.py *.pyw 2>/dev/null | xargs)"
return
fi
}
# keep around for compatibility
_poseur_to_completion() {
_poseur
}
complete -o bashdefault -o default -F _poseur poseur