forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion.bash
79 lines (74 loc) · 2.91 KB
/
completion.bash
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
# Bash completion for "crystal" command.
# Written by Sergey Potapov <[email protected]>.
# Get list of crystal files or directories, that match $pattern
_crystal_compgen_files(){
local pattern=$1
compgen -f -o plusdirs -X '!*.cr' -- $pattern
}
_crystal()
{
local program=${COMP_WORDS[0]}
local cmd=${COMP_WORDS[1]}
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="init build docs eval play run spec tool help version --help --version"
case "${cmd}" in
init)
if [[ "${prev}" == "init" ]] ; then
COMPREPLY=( $(compgen -W "app lib" -- ${cur}) )
else
COMPREPLY=( $(compgen -f ${cur}) )
fi
;;
compile)
if [[ ${cur} == -* ]] ; then
local opts="--cross-compile --debug --emit --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --single-module --threads --target --verbose --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
;;
run)
if [[ ${cur} == -* ]] ; then
local opts="--debug --define --emit --format --help --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --stats --single-module --threads --verbose"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
;;
tool)
if [[ ${cur} == -* ]] ; then
local opts="--no-color --prelude --define --format --cursor"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
if [[ "${prev}" == "tool" ]] ; then
local subcommands="context format hierarchy implementations types"
COMPREPLY=( $(compgen -W "${subcommands}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
fi
;;
play)
if [[ ${cur} == -* ]] ; then
local opts="--port --binding --verbose --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
;;
docs|eval|spec|version|help)
# These commands do not accept any options nor subcommands
COMPREPLY=( $(compgen -f ${cur}) )
;;
*)
# When any of sumbcommands matches directly
if [[ "${prev}" == "${program}" && $(compgen -W "${commands}" -- ${cur}) ]] ; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
esac
return 0
}
complete -F _crystal -o filenames crystal