-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmix_autocomplete.zsh
60 lines (47 loc) · 1.15 KB
/
mix_autocomplete.zsh
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
#!/usr/bin/env zsh
if [[ ! -o interactive ]]; then
return
fi
function _mix() {
if [[ ! -e "mix.exs" ]]; then
return
fi
local mix_md5
local completions
local current_mix_md5
local recalculate=true
if type "md5" >/dev/null; then
current_mix_md5=`md5 -q mix.exs`
elif type "md5sum" >/dev/null; then
current_mix_md5=`md5sum mix.exs | awk '{ print $1 }'`
else
# no either md5 or md5sum
return 1
fi
if _retrieve_cache mix; then
if [[ $mix_md5 == $current_mix_md5 ]]; then
recalculate=false
fi
fi
if [[ $recalculate == "true" ]]; then
mix_md5=$current_mix_md5
# Pre-compile the project and check status
mix compile >/dev/null 2>&1
if [[ $? -eq 1 ]]; then
# Project compilation failed --
# show a message explaining why we can't show completions?
return 1
fi
completions="$(
mix run -e '
Mix.Task.load_all
|> Enum.map(&(Mix.Task.task_name &1))
|> Enum.sort
|> Enum.join(" ")
|> IO.puts
')"
_store_cache mix mix_md5 completions
fi
_arguments "1: :(${completions})"
}
compdef _mix mix