forked from iarsystems/bx-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiarbuild-autocompletion.bash
executable file
·91 lines (83 loc) · 1.84 KB
/
iarbuild-autocompletion.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
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
#
# Copyright (c) 2020-2021 IAR Systems AB
#
# iarbuild-autocompletion.bash
#
# Provides Bash Autocompletion for IARBuild
#
# See LICENSE.md for detailed license information
#
__iarbuild()
{
local cur prev cmds msgs nprocs
local ewp
local opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmds="-clean -build -make -cstat_analyze -cstat_clean"
msgs="error warnings info all"
opts="-parallel -log -varfile"
nprocs=$(echo $(seq 2 $(nproc)))
case $COMP_CWORD in
1)
compopt -o nospace
local IFS=$'\n'
local LASTCHAR=' '
COMPREPLY=($(compgen -o plusdirs -f -X '!*.@(EWP|ewp)' -- "${COMP_WORDS[COMP_CWORD]}"))
if [ ${#COMPREPLY[@]} = 1 ]; then
[ -d "$COMPREPLY" ] && LASTCHAR=/
COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
else
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
[ -d "${COMPREPLY[$i]}" ] && COMPREPLY[$i]=${COMPREPLY[$i]}/
done
fi
return 0
;;
2)
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
return 0
;;
3)
ewp=${COMP_WORDS[1]}
buildcfg=$( echo $(grep -A1 '<configuration>' ${ewp} | grep -oP '(?<=<name>).*?(?=</name>)') )
COMPREPLY=( $(compgen -W "${buildcfg}" -- ${cur}) )
return 0
;;
*)
case ${prev} in
"-parallel")
COMPREPLY=( $(compgen -W "${nprocs}" -- ${cur} ))
return 0
;;
"-log")
COMPREPLY=( $(compgen -W "${msgs}" -- ${cur} ))
return 0
;;
"-varfile")
COMPREPLY=( $(compgen -f -X '!*.@(argvars|ARGVARS)' -- ${cur} ))
return 0
;;
esac
# prevent repeated suggetions
for removal in "${COMP_WORDS[@]}"; do
case ${removal} in
"-parallel")
opts=${opts//-parallel/}
;;
"-log")
opts=${opts//-log/}
;;
"-varfile")
opts=${opts//-varfile/}
;;
esac
done
COMPREPLY=( $(compgen -W "${opts}" -- ${cur} ))
return 0
;;
esac
}
complete -F __iarbuild iarbuild