From 552927d25f5c552f8502b87a55169e5ec63e8dcf Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 29 May 2022 12:42:26 +0200 Subject: [PATCH] support profiles and step aliases with spaces --- sequencer.sh | 34 +++++++++++++++------------------- sqn-completion.bash | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/sequencer.sh b/sequencer.sh index c9285bd..cb42a22 100755 --- a/sequencer.sh +++ b/sequencer.sh @@ -134,7 +134,7 @@ helpApi(){ sequencer.sh API The sequencer.sh build-in functions are available in all sequence functions: -- step_config +- seq_config If optional step_config is defined in the sequence, it will be called once before execution of steps. - step_[1-${_sqr_stepMax}]_info - step_[1-${_sqr_stepMax}]_alias @@ -142,14 +142,14 @@ The sequencer.sh build-in functions are available in all sequence functions: sequencer.sh global variables: - \$SEQUENCER_ARGS + \${sqr_args} String of all given options \$SEQ_CONFIG_HOME Path to user specific seq configuration directory - \$SEQ_CONFIG_FILE + \${seq_configFile} Path to user specific seq configuration file Will be empty if unused - \$SEQ_PROFILE_NAME + \${seq_profileName} Profile string selected with -p argument sequencer.sh build-in functions: @@ -1108,8 +1108,6 @@ displayHelp() { # show only steps and aliases starting with [FILTER STRING] listSteps() { local locAlias= - local aList=() - local aSearch="${1:-}" for ((i=1; i<=_sqr_stepMax; i++)); do # Display step reference in help if step function exists @@ -1122,14 +1120,11 @@ listSteps() { locAlias="$i" fi - if [ -z "$aSearch" ]; then - aList+=("$locAlias") - elif [[ "$locAlias" =~ ^$aSearch ]]; then - aList+=("$locAlias") + # $1 = filter regex + if [[ "$locAlias" =~ ^${1:-.*} ]]; then + printf '%s\n' "${locAlias}" fi done - - [ ${#aList[@]} -ne 0 ] && printf '%s\n' "${aList[*]}" } # listProfiles [OPTION] [SEARCH] @@ -1138,18 +1133,15 @@ listSteps() { # -q : only check for profile support listProfiles() { local file= - local profiles=() if [[ ${_sqr_configDirName} == $(basename "${_sqr_configRoot}") ]] ; then error "${seq_name} does not have configuration profiles" return 1 fi [[ "${1:-}" == "-q" ]] && return 0 - #for file in $(ls "${_sqr_configRoot}" 2>/dev/null); do for file in "${_sqr_configRoot}"/* ; do file="$(basename -- "${file}")" - [[ ${file%.*} =~ ^${1:-".*"} ]] && profiles+=("${file%.*}") + [[ ${file%.*} =~ ^${1:-.*} ]] && printf '%s\n' "${file%.*}" done - printf '%s\n' "${profiles[*]}" } # showVersion @@ -1438,6 +1430,9 @@ exep() { # Check if sequence is compatible sqr::compatible() { + if ! exists "sqr_minVersion"; then + sqr_minVersion="${VERSION_SEQREV:-0}" + fi if [ -z "${sqr_minVersion:-}" ] ; then warning "No sequence revision found. Trying anyway..." else @@ -1447,8 +1442,9 @@ sqr::compatible() { return 1 fi # exclude older versions if needed - if [ -n "${sqr_minVersion}" ] && [[ ${sqr_minVersion} -lt 3 ]] ; then - error "Unsupported sequence revision (addConf)" + if [ -n "${sqr_minVersion}" ] && [[ ${sqr_minVersion} -le 15 ]] ; then + error "Unsupported sequence revision (major changes in version 16)" + error -a "(Use 'seqUpgrade.sh $(readlink -f -- $0)' for a basic upgrade)" showVersion return 1 fi @@ -1551,7 +1547,7 @@ sqr::main() { [ ${_sqr_configEdit} -ne 0 ] && [ -z "${1:-}" ] && LOG_LEVEL=1 if [ -z "${1:-}" ] && [ $quickStartOne -eq 0 ] ; then - if ! quiet ; then + if ! quiet && [[ ${LOG_LEVEL} -ge $log_info ]] ; then # Empty -> show help displayHelp fi diff --git a/sqn-completion.bash b/sqn-completion.bash index 0b4d699..a8488f6 100755 --- a/sqn-completion.bash +++ b/sqn-completion.bash @@ -3,6 +3,7 @@ _sqn_completions() { + local tempreply=() # Current search string local cur=${COMP_WORDS[COMP_CWORD]} # Extract alias command with buildins same as: @@ -35,7 +36,11 @@ _sqn_completions() # provide completion for option with parameter -p|--profile) # sequencer.sh provides creation of a profile list with search functionality - read -r -a COMPREPLY <<<"$( "$curCmd" -pl "${cur}" 2>/dev/null)" + IFS=$'\n' read -r -d '' -a tempreply <<<"$( "$curCmd" -pl "${cur}" 2>/dev/null)" + for comp in "${tempreply[@]}" ; do + # Support for profile names with spaces + COMPREPLY+=("$(printf '%q' "${comp}")") + done ;; *) # Stop after step selection (last argument which is not an option (starting with "-|+") @@ -50,7 +55,12 @@ _sqn_completions() esac fi # sequencer.sh provides creation of a step list with search functionality - read -r -a COMPREPLY <<<"$( "$curCmd" -ls "$cur" )" + #read -r -a COMPREPLY <<<"$( "$curCmd" -ls "$cur" )" + IFS=$'\n' read -r -d '' -a tempreply <<<"$( "$curCmd" -ls "$cur" )" + for comp in "${tempreply[@]}" ; do + # Support for aliases with spaces + COMPREPLY+=("$(printf '%q' "${comp}")") + done ;; esac ;;