-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path_cado
97 lines (91 loc) · 2.28 KB
/
_cado
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
this_project=`cat MANIFEST | sed -n '/NAME/s/.*: //p'`
if [[ ${this_project} == gem ]] ; then
cado_commands=(
cmake
cmake-static
cmake-all
cmake-debug
cmake-debug-extra
cmake-mach
cmake-mach-static
cmake-all-mach
cmake-mach-debug
build
work
install
package
help
)
else
cado_commands=(
cmake
cmake-static
cmake-all
cmake-debug
cmake-debug-extra
build
work
install
package
help
)
fi
#
# If not using the IF in _complete_targets, then we could list only some "favorite" targets
# and save the user from getting a large amount of targets.
# Examples:
favorite_makefile_targets=(
work
maingemdm
rpnphy
rmn
modelutils
install
# ...
)
_cado(){
local cur prev words cword
_init_completion || return
COMPREPLY=()
if (( cword == 1 )) ; then
COMPREPLY=($(compgen -W "${cado_commands[*]}" -- ${cur}))
elif [[ "${words[1]}" == "build" ]] ; then
_complete_targets build-${GEM_ARCH}
fi
}
_complete_targets(){
#
# In the original shortcut Makefile, tab completion would only complete
# targets of that Makefile. This call to _get_makefile_targets would
# get over a hundred results. Perhaps it is better to only list some
# targets in the targets array above instead and not have this if
#
# if [[ -d "${1}" ]] ; then
# _get_makefile_targets ${1}
# fi
COMPREPLY+=( $(compgen -W "${favorite_makefile_targets[*]}" -- "${cur}") )
}
#
# I just found the code in the make completion script with a tiny bit of
# modifications. This gives too much stuff though, people would probably
# not want that.
#
_get_makefile_targets(){
local build_dir=$1
#
# Completion for `make` is normally lazy loaded the first time you invoke
# completion for `make in a given shell. This provides the function
# _make_target_extract_script used below
#
if [[ "$(type -t _make)" != function ]] ; then
_completion_loader make
fi
#
local reset=$(shopt -po posix); set +o posix
COMPREPLY=( $(cd ${build_dir} && LC_ALL=C \
make -npq __BASH_MAKE_COMPLETION__=1 \
.DEFAULT 2>/dev/null | \
command sed -nf <(_make_target_extract_script -- "${cur}") ) )
$reset
}
complete -F _cado cado