From 8b3b5b0050695316c1d6969a143fb7a473d832b2 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 22 Oct 2018 20:08:47 +0200 Subject: Add bash completion for clm --- clean/.bash_completion.d/clm | 50 ++++++++++++++++++++++++++++++++++++++++++++ system/.bash_completion | 3 +++ 2 files changed, 53 insertions(+) create mode 100644 clean/.bash_completion.d/clm create mode 100644 system/.bash_completion diff --git a/clean/.bash_completion.d/clm b/clean/.bash_completion.d/clm new file mode 100644 index 0000000..85b77af --- /dev/null +++ b/clean/.bash_completion.d/clm @@ -0,0 +1,50 @@ +_clm() +{ + local cur prev opts + COMPRREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + 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 -ns -no-opt-link -l -sl -e -E -aC -h -s -b -sc -t -nt -gc -ngc -st -nst -nr -gcm -gcc -gcf -gci -optabc -bytecode" + + case $prev in + "-IL") + # Complete Clean libraries + opts="$(find "$CLEAN_HOME/lib" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)" + COMPREPLY=($(compgen -W "$opts" -- $cur)) + return 0 + ;; + "-I") + # Complete directories + _filedir + for index in "${!COMPREPLY[@]}"; do + [ -d "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]' + done + return 0 + ;; + "-l" | "-sl") + # Complete files + _filedir + for index in "${!COMPREPLY[@]}"; do + [ -f "${COMPREPLY[index]}" ] || unset -v 'COMPREPLY[$index]' + done + return 0 + ;; + "-P" | "-e" | "-E" | "-h" | "-s" | "-gcf" | "-gci") + # Complete nothing + return 0 + ;; + esac + + if [[ $cur == -* ]]; then + # Complete options + COMPREPLY=($(compgen -W "$opts" -- $cur)) + return 0 + else + # Main module; complete icl module names + opts="$(find -name '*.icl' -maxdepth 4 -type f -print 2>/dev/null | sed 's:^\./::;s:/:.:g;s:\.icl$::' | grep -v '[- ]')" + COMPREPLY=($(compgen -W "$opts" -- $cur)) + return 0 + fi +} +complete -F _clm clm diff --git a/system/.bash_completion b/system/.bash_completion new file mode 100644 index 0000000..21daa89 --- /dev/null +++ b/system/.bash_completion @@ -0,0 +1,3 @@ +for f in ~/.bash_completion.d/*; do + . "$f" +done -- cgit v1.2.3