summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2019-08-08 15:08:16 +0200
committerJonathan Bauer2019-08-08 15:08:16 +0200
commit7a55a4443b188cbb31788230f5ab4d54fca5cf35 (patch)
tree46ef239cd4c290fd8451a423e7fde52928c3141c
parent[dhcpc-busybox] TIL: ip route replace (diff)
downloadmltk-7a55a4443b188cbb31788230f5ab4d54fca5cf35.tar.gz
mltk-7a55a4443b188cbb31788230f5ab4d54fca5cf35.tar.xz
mltk-7a55a4443b188cbb31788230f5ab4d54fca5cf35.zip
bash completion \o/
-rw-r--r--data/mltk.bash_completion34
1 files changed, 34 insertions, 0 deletions
diff --git a/data/mltk.bash_completion b/data/mltk.bash_completion
new file mode 100644
index 00000000..32effea9
--- /dev/null
+++ b/data/mltk.bash_completion
@@ -0,0 +1,34 @@
+pls() {
+ ls --color=never "$1"
+}
+_mltk_module() {
+ local path="$(readlink -f ${COMP_WORDS[0]})"
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ local prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ # if '-n' present, stop here
+ if grep -qE '\s+-n\s?' <<< "$COMP_LINE" ; then
+ return
+ fi
+
+ # if 2 words, needs to be a target
+ if [ "${#COMP_WORDS[@]}" -eq 2 ]; then
+ COMPREPLY=($(compgen -W "$(pls $(dirname $path)/core/targets) -n" -- "$cur"))
+ return
+ fi
+
+ # actions now:
+ local defaults="-b -c"
+ # only add '-d' if not present already
+ if ! grep -qE '\s+-d\s+' <<< "$COMP_LINE" ; then
+ defaults="$defaults -d"
+ fi
+ COMPREPLY=($(compgen -W "$defaults" -- "$cur"))
+
+ # now it can be either actions or modules for the targets
+ COMPREPLY+=($(compgen -W "$(pls $(dirname $path)/core/targets/${COMP_WORDS[1]})" -- "$cur"))
+ return
+}
+
+complete -F _mltk_module ./mltk
+