completion
[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 -maxdepth 1 -type d -exec basename {} \;)"
14 COMPREPLY=($(compgen -W "$opts" -- $cur))
15 return 0
16 ;;
17 "-I")
18 # Complete directories
19 _filedir
20 for index in "${!COMPREPLY[@]}"; do
21 [ -d "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]'
22 done
23 return 0
24 ;;
25 "-l" | "-sl")
26 # Complete files
27 _filedir
28 for index in "${!COMPREPLY[@]}"; do
29 [ -f "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]'
30 done
31 return 0
32 ;;
33 "-P" | "-e" | "-E" | "-h" | "-s" | "-gcf" | "-gci")
34 # Complete nothing
35 return 0
36 ;;
37 esac
38
39 if [[ $cur == -* ]]; then
40 # Complete options
41 COMPREPLY=($(compgen -W "$opts" -- $cur))
42 return 0
43 else
44 # Main module; complete icl module names
45 opts="$(find -name '*.icl' -maxdepth 4 -type f -print 2>/dev/null | sed 's:^\./::;s:/:.:g;s:\.icl$::' | grep -v '[- ]')"
46 COMPREPLY=($(compgen -W "$opts" -- $cur))
47 return 0
48 fi
49 }
50 complete -F _clm clm