-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfunction
More file actions
73 lines (73 loc) · 2.85 KB
/
Copy pathfunction
File metadata and controls
73 lines (73 loc) · 2.85 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
send_completions() {
echo $'# completely completion -*- shell-script -*-'
echo $''
echo $'# This bash completions script was generated by'
echo $'# completely (https://github.com/bashly-framework/completely)'
echo $'# Modifying it manually is not recommended'
echo $''
echo $'_completely_completions_filter() {'
echo $' local words=("$@")'
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
echo $' local result=()'
echo $' local want_options=0'
echo $''
echo $' # words the user already typed (excluding the command itself)'
echo $' local used=()'
echo $' if ((COMP_CWORD > 1)); then'
echo $' used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")'
echo $' fi'
echo $''
echo $' # Completing an option: offer everything.'
echo $' # Completing a non-option: drop options and already-used words.'
echo $' [[ "${cur:0:1}" == "-" ]] && want_options=1'
echo $' for word in "${words[@]}"; do'
echo $' if ((!want_options)); then'
echo $' [[ "${word:0:1}" == "-" ]] && continue'
echo $''
echo $' for u in "${used[@]}"; do'
echo $' if [[ "$u" == "$word" ]]; then'
echo $' continue 2'
echo $' fi'
echo $' done'
echo $' fi'
echo $''
echo $' # compgen -W expects shell-escaped words in one space-delimited string.'
echo $' printf -v word \'%q\' "$word"'
echo $' result+=("$word")'
echo $' done'
echo $''
echo $' echo "${result[*]}"'
echo $'}'
echo $''
echo $'_completely_completions() {'
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
echo $' local compwords=()'
echo $' if ((COMP_CWORD > 0)); then'
echo $' compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")'
echo $' fi'
echo $' local compline="${compwords[*]}"'
echo $''
echo $' COMPREPLY=()'
echo $''
echo $' case "$compline" in'
echo $' \'generate\'*)'
echo $' # shellcheck disable=SC2046 # intentional splitting for dynamic $(...) completions'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_completely_completions_filter "--help" "--force")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'init\'*)'
echo $' # shellcheck disable=SC2046 # intentional splitting for dynamic $(...) completions'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help")" -- "$cur")'
echo $' ;;'
echo $''
echo $' *)'
echo $' # shellcheck disable=SC2046 # intentional splitting for dynamic $(...) completions'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help" "--version" "init" "generate")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $'} &&'
echo $' complete -F _completely_completions completely'
echo $''
echo $'# ex: filetype=sh'
}