From 1f151e0824c9cdc48a30f5cc54b55d1264ecbb6b Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Mon, 28 Nov 2022 14:30:26 +0100 Subject: bash autocompletion: implement tab-completion for repo provided via --main. Note that it works only if repo is a file repository --- share/just_complete.bash | 81 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 12 deletions(-) diff --git a/share/just_complete.bash b/share/just_complete.bash index c62d446a..d6640c5f 100644 --- a/share/just_complete.bash +++ b/share/just_complete.bash @@ -1,3 +1,5 @@ +########################### just completion + _just_subcommand_options(){ local cmd=$1 for w in $(just $cmd --help) @@ -10,7 +12,8 @@ _just_targets(){ command -v python3 &>/dev/null || return python3 - </dev/null)) + # look for -C and --main + for i in "${!COMP_WORDS[@]}" + do + if [[ "${COMP_WORDS[i]}" == "--main" ]] + then + main="${COMP_WORDS[$((++i))]}" + fi + if [[ "${COMP_WORDS[i]}" == "-C" ]] || [[ "${COMP_WORDS[i]}" == "--repository-config" ]] + then + conf="${COMP_WORDS[$((++i))]}" + fi + done + # if $conf is empty and this function is invoked by just-mr + # we use the auto-generated conf file + if [ -z "$conf" ]; then conf="${justmrconf}"; + fi + local _targets=($(_just_targets "$conf" "$main" "$prev" 2>/dev/null)) COMPREPLY=($(compgen -f -W "${_opts[*]} ${_targets[*]}" -- $word )) compopt -o plusdirs -o bashdefault -o default else @@ -55,6 +108,8 @@ _just_completion(){ } complete -F _just_completion just + +########################### just-mr completion _just-mr_options(){ local cmd=$1 for w in $($cmd --help 2>/dev/null) @@ -117,8 +172,10 @@ _just-mr_completion(){ COMPREPLY=($(compgen -f -W "${_opts[*]} ${_repos[*]}" -- $word )) elif [[ "$cmd" =~ ^(version|build|analyse|describe|install-cas|install|rebuild) ]] then - # just subcommand options and modules/targets - _just_completion + # just subcommand options and modules/targets eventually using the + # auto-generated configuration + local justmrconf=$(just-mr setup --all 2>/dev/null) + _just_completion else # just-mr top-level options local _opts=($(_just-mr_options "just-mr")) -- cgit v1.2.3