-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvim-pack-complete
More file actions
executable file
·179 lines (173 loc) · 4.51 KB
/
vim-pack-complete
File metadata and controls
executable file
·179 lines (173 loc) · 4.51 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#! /usr/bin/env bash
repo_dir=$HOME/.vim/pack/git-plugins
contains_single() {
local array="$1[@]"
local seeking=$2
local in=0
for element in "${!array}"; do
if [[ "$element" == "$seeking" ]]; then
in=1
break
fi
done
return $in
}
contains() {
local var
local in=0
for var in "${@:2}"; do
contains_single "$1" "$var"
if [ "$?" -eq 1 ]; then
in=1
break
fi
done
return $in
}
_vim_pack_tab_complete() {
local cur prev
compopt -o nospace
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
words=""
if [ "$COMP_CWORD" -eq "1" ]; then
words="get install list remove update upgrade export import sync"
COMPREPLY=( $(compgen -W "$words" -- "$cur") )
return 0;
else
if [[ "$prev" == '--'* && "$cur" == '=' ]] ; then
compopt -o filenames
COMPREPLY=(*)
return 0
fi
# Handle --xxxxx=path
if [[ "$prev" == '=' ]] ; then
# Unescape space
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
if contains COMP_WORDS "--git-dir" "-d"; then
words="$words -d --git-dir="
else
if [[ "$prev" == "-d" ]];then
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
next=0
for var in ${COMP_WORDS[*]}; do
if (( next == 1 )); then
next=2
elif (( next == 2 )); then
repo_dir=$var
fi
if [[ $var == '-d' ]]; then
next=2
fi
if [[ $var == '--git-dir' ]]; then
next=1
fi
done
fi
if contains COMP_WORDS '--silent' '-s' '--verbose' '-v'; then
words="$words -s --silent -v --verbose"
fi
case "${COMP_WORDS[1]}" in
get)
if contains COMP_WORDS 'opt' 'start'; then
words="$words opt start"
fi
;;
install)
if contains COMP_WORDS 'opt' 'start'; then
words="$words opt start"
fi
;;
list)
if [[ "$(compgen -W "${words}" -- "${cur}")" == '' ]]; then
# Expand tilder to $HOME
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
;;
remove)
contains COMP_WORDS 'opt'
local opt=$?
contains COMP_WORDS 'start'
local start=$?
if (( opt == 1 )) ; then
words="$words $(ls "$repo_dir/opt")"
elif (( start == 1 )); then
words="$words $(ls "$repo_dir/start")"
else
words="$words opt start"
fi
;;
update)
if contains COMP_WORDS '-g' '--gnu-parallel' '-m' '--more-parallel' '-l' '--loop'; then
words="$words -g --gnu-parallel -m --more-parallel -l --loop"
fi
;;
upgrade)
if contains COMP_WORDS '-g' '--gnu-parallel' '-m' '--more-parallel' '-l' '--loop'; then
words="$words -g --gnu-parallel -m --more-parallel -l --loop"
fi
;;
export)
if [[ "$(compgen -W "${words}" -- "${cur}")" == '' ]]; then
# Expand tilder to $HOME
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
;;
import)
if contains COMP_WORDS '-g' '--gnu-parallel' '-m' '--more-parallel' '-l' '--loop'; then
words="$words -g --gnu-parallel -m --more-parallel -l --loop"
fi
if [[ "$(compgen -W "${words}" -- "${cur}")" == "" ]]; then
# Expand tilder to $HOME
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
;;
sync)
if contains COMP_WORDS '-g' '--gnu-parallel' '-m' '--more-parallel' '-l' '--loop'; then
words="$words -g --gnu-parallel -m --more-parallel -l --loop"
fi
if [[ "$(compgen -W "${words}" -- "${cur}")" == "" ]]; then
# Expand tilder to $HOME
cur=$(realpath "${cur//\\ / }")
# Show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
;;
*)
esac
mapfile -t COMPREPLY < <(compgen -W "${words}" -- "${cur}")
fi
return 0
}
complete -F _vim_pack_tab_complete vim-pack