From 91bb5912cd413eb3315c15b3a18049ec781b583f Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 19 Oct 2022 15:31:34 +0200 Subject: share: Provide bash completion for just-mr --- share/just-mr_complete.bash | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 share/just-mr_complete.bash (limited to 'share') diff --git a/share/just-mr_complete.bash b/share/just-mr_complete.bash new file mode 100644 index 00000000..c8d3f4f1 --- /dev/null +++ b/share/just-mr_complete.bash @@ -0,0 +1,102 @@ +_just-mr_options(){ + local cmd=$1 + for w in $($cmd --help 2>/dev/null) + do + [[ $w =~ ^-. ]] && printf "%s\n" ${w//,/" "} + done +} + +_just-mr_parse_subcommand() { + local readonly FLAGS=("--help\n-h\n--norc\ndo") # treat 'do' as flag + local readonly OPTIONS=("--distdir\n--just\n--local-build-root\n--main\n--rc\n-C\n-L") + shift + while [ -n "$1" ]; do + if echo -e "$FLAGS" | grep -q -- "^$1$"; then shift; continue; fi + if echo -e "$OPTIONS" | grep -q -- "^$1$"; then shift; shift; continue; fi + if [ "$1" = "--" ]; then shift; fi + break + done + echo "$1" +} + +_just-mr_repos(){ + command -v python3 &>/dev/null || return + local CONF=$(just-mr setup --all 2>/dev/null) + if [ ! -f "$CONF" ]; then return; fi + python3 - </dev/null || return + python3 - <