improve clm modules
[dotfiles.git] / shell / .bash_completion.d / clm
1 _clm()
2 {
3 local cur prev opts
4 COMPRREPLY=()
5 cur="${COMP_WORDS[COMP_CWORD]}"
6 prev="${COMP_WORDS[COMP_CWORD-1]}"
7
8 opts="-I -IL -P -w -nw -d -nd -sa -nsa -mv -ms -O -PO -S -PS -ABC -PABC -c -lt -nlt -lat -nlat -lset -ci -nci -ou -nou -fusion -nfusion -pt -npt -desc -exl -tst -funcmayfail -varnotused -funcnotused -nowarn -ns -no-opt-link -l -sl -e -E -aC -h -s -b -sc -t -nt -gc -ngc -st -nst -nr -gcm -gcc -gcf -gci -dynamics -nortsopts -p -pic -optabc -bytecode"
9
10 case $prev in
11 "-IL")
12 # Complete Clean libraries
13 opts="$(find "$CLEAN_HOME/lib" -mindepth 1 -type d -not -name exe -regex ".*/lib/\([^/]*\|Platform/Deprecated/[^/]*\)" | cut -c $((${#CLEAN_HOME}+6))-)"
14
15
16
17 COMPREPLY=($(compgen -W "$opts" -- $cur))
18 return 0
19 ;;
20 "-I")
21 # Complete directories
22 _filedir
23 for index in "${!COMPREPLY[@]}"; do
24 [ -d "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]'
25 done
26 return 0
27 ;;
28 "-l" | "-sl")
29 # Complete files
30 _filedir
31 for index in "${!COMPREPLY[@]}"; do
32 [ -f "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]'
33 done
34 return 0
35 ;;
36 "-P" | "-e" | "-E" | "-h" | "-s" | "-gcf" | "-gci")
37 # Complete nothing
38 return 0
39 ;;
40 esac
41
42 if [[ $cur == -* ]]; then
43 # Complete options
44 COMPREPLY=($(compgen -W "$opts" -- $cur))
45 return 0
46 else
47 # Main module; complete icl module names
48 opts="$(find -name '*.icl' -maxdepth 4 -type f -print 2>/dev/null | sed 's:^\./::;s:/:.:g;s:\.icl$::' | grep -v '[- ]')"
49 COMPREPLY=($(compgen -W "$opts" -- $cur))
50 return 0
51 fi
52 }
53 complete -F _clm clm