From 7292ee8ec6ebcec31acfd0e0849cf165668f4ac2 Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Thu, 9 Jul 2020 21:28:47 +0200 Subject: [PATCH] Tools: completion bash: fix and simplify frames completion --- Tools/completion/bash/_sim_vehicle | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Tools/completion/bash/_sim_vehicle b/Tools/completion/bash/_sim_vehicle index 2c6488b130..5414df3996 100644 --- a/Tools/completion/bash/_sim_vehicle +++ b/Tools/completion/bash/_sim_vehicle @@ -65,7 +65,7 @@ _sim_vehicle() { # get the calling program, remove anything after the space == all commands arguments local caller; caller=$(echo $@ | sed 's/ .*//g'); # get options between "vehicle type " and closing ")", remove line return, remove spaces, anything before the opening (, remove the "|" and closing ")" - opts=$($caller --help | sed -n '/vehicle type/,/)/p' | sed -e '1d' | tr -d '()' | tr '\n' ' ' | sed -e 's/ //g' -e 's/.*(//g' -e 's/[|)]/ /g') + opts=$($caller --list-vehicle) COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 ;; @@ -75,16 +75,13 @@ _sim_vehicle() { # Get everything between "frame type" and "-C", remove first and last line, get line starting with caracters and ": " sequence, remove spaces and : local supported_vehicle_list=$($caller --help | sed -n '/frame type/,/-C/p' | sed -e '1d' -e '$d' | sed -n 's/\(.*: \).*/\1/p' | sed -e 's/ //g' -e 's/://g') local frames; - local count=1; for v in $supported_vehicle_list do if [[ ${COMP_WORDS[@]} == *"$v"* ]] then - # Get everything between "frame type" and "-C", remove first and last line and change starting space by " :", change newlines to space, remove spaces then change vehicle type enclose by ":" by newline and change "|" by space, remove first line, get line "count" that match supported_vehicle_list[count] - frames=$($caller --help | sed -n '/frame type/,/-C/p' | sed -e '1d' -e '$d' -e 's/^\s*A/ :A/g' | tr '\n' ' ' | sed -e 's/ //g' -e 's/:\w*:/\n/g' -e 's/[|]/ /g' | sed '1d' | sed "${count}q;d") + frames=$($caller --list-frame "$v") break fi - count=$(( $count + 1 )) done COMPREPLY=($(compgen -W "${frames}" -- ${cur})) return 0