From 58a8ec6eae43fe93b23afffb1a6ac25fc7f5c3b9 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Wed, 9 Feb 2022 15:44:22 +0100 Subject: [PATCH] Ability to show sqn_ alias in sequencer help outColor accepts a custom color number (0-255) --- sequencer/sequencer.sh | 16 ++++++++-------- sqnall-completion.bash | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index b7a3c52..fdf9b35 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -9,7 +9,7 @@ VERSION_REV=14 VERSION_MAJOR=0 -VERSION_MINOR=1 +VERSION_MINOR=2 ## Start of generic script part @@ -60,8 +60,10 @@ SAVE_POS= ;[ -t 1 ] && SAVE_POS='\033[3D\033[s\033[3C' RESTORE_POS= ;[ -t 1 ] && RESTORE_POS='\033[u' helpSequencer() { + local scriptName=${0##*/} + [ ! -z "$_SQN_ALIAS" ] && scriptName="$_SQN_ALIAS" cat <&2 echo "$@"; outColor none; } # outColor [BACKGROUND COLOR] outColor() { [ ! -t 1 ] && return 0 + [ -z "$1" ] && tput sgr0 && return 0 case "$1" in black) tput setaf 0;; @@ -294,8 +297,7 @@ outColor() { white) tput setaf 7;; *) - tput sgr0 - return;; + tput setaf $1;; esac case "$2" in @@ -510,8 +512,7 @@ initSeqConfig() { # Create config subdir in users home if [ ! -e "$configDir/" ] ; then echoseq -n " [I] Creating $(realpath $configDir)..." - exe mkdir -p "$configDir" && echoseq "Ok" || echoseq "Nok" - exe chmod 700 "$configDir" + exe install -m 700 -d "$configDir" && echoseq "Ok" || echoseq "Nok" fi SEQ_CONFIG_HOME="$configDir" @@ -538,9 +539,8 @@ initSeqConfig() { return 0 fi - exe cp -ar "$configTemplate" "$configLoc" + exe install -m 600 -T "$configTemplate" "$configLoc" endReturn -o $? "Failed to create configuration" - exe chmod 600 "$configLoc" if [ $sourceAlways -eq 0 ] ; then if [ $SEQ_CONFIG_EDIT -eq 0 ] ; then diff --git a/sqnall-completion.bash b/sqnall-completion.bash index c8b7fe1..9f8f5d3 100755 --- a/sqnall-completion.bash +++ b/sqnall-completion.bash @@ -5,14 +5,27 @@ _sqnall_completions() # Current search string local cur=${COMP_WORDS[COMP_CWORD]} # Extract alias command with buildins same as: - # local curCmd="$(alias $1 | sed "s/^alias.*='\(.*\)'$/\1/")" + # local curCmd="$(alias $1 | sed "s/^alias.*\" \(.*\)'$/\1/")" local curCmd="$(alias "$1")" - curCmd="${curCmd#*=\'}" + curCmd="${curCmd##*\" }" curCmd="${curCmd%\'*}" COMPREPLY=() case "$cur" in -*) - COMPREPLY=( $( compgen -W '-c -d -h -ha -ls -p -pl -q -qq -s -v --version' -- $cur ) );; + COMPREPLY=( $( compgen -W '\ + -a --all \ + -c --config \ + -d --dry-run \ + -h --help \ + -ha --helpapi \ + -ls --liststeps \ + -p --profile \ + -pl \ + -q --quiet \ + -qq \ + -s --single \ + -v --verbose \ + --version' -- $cur ) );; *) # Stop after step selection (last argument which is not an option; starting with "-") (( COMP_CWORD > 1 )) && [[ ! "${COMP_WORDS[((COMP_CWORD - 1))]}" =~ ^- ]] && return @@ -32,7 +45,7 @@ installCompletion() { SEQLIST[$i]="${SEQLIST[$i]##*/}" SEQLIST[$i]="${SEQLIST[$i]%.*}" SEQSHORT[$i]="${SEQPREFIX}${SEQLIST[$i]}" - alias ${SEQSHORT[$i]}="$SEQBASE/${SEQLIST[$i]}.sh" + alias ${SEQSHORT[$i]}="_SQN_ALIAS=\"${SEQSHORT[$i]}\" $SEQBASE/${SEQLIST[$i]}.sh" done complete -o nosort -o bashdefault -o default -F _sqnall_completions ${SEQSHORT[@]} }