sequencer - list profiles (-pl) with filter function

This commit is contained in:
2022-04-21 22:40:59 +02:00
parent 41c48407a8
commit 1dfe86e69b

View File

@@ -9,7 +9,7 @@
VERSION_REV=15
VERSION_MAJOR=3
VERSION_MINOR=0
VERSION_MINOR=1
## Start of generic script part
@@ -21,22 +21,21 @@ ERNO=0
SEQUENCER_ARGS=
STEP_ARGS=
STEP_RETURN=255
MAX_STEP=512
readonly MAX_STEP=512
ALIAS=
CONTEXT_HELP=0
CONTEXT_EXE=0
SEQ_NAME="$_SQN_ALIAS"
[ -z "$SEQ_NAME" ] && SEQ_NAME="${0##*/}"
SEQ_CONFIG_EDIT=0
SEQ_CONFIG_NAME=".seqs"
readonly SEQ_CONFIG_NAME=".seqs"
SEQ_CONFIG_FILE=
SEQ_CONFIG_HOME="$HOME/$SEQ_CONFIG_NAME"
SEQ_PROFILE_SUPPORT=0
SEQ_PROFILE_NAME=
SEQ_PROFILE_LIST=0
TEMPLATE_NAME=seqTemplateExample.sh
MISSING_CONF=missingConf.log
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
SEQ_PROFILE_LIST=
readonly TEMPLATE_NAME=seqTemplateExample.sh
readonly MISSING_CONF=missingConf.log
readonly VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
DEFAULT_EDITOR_SYSTEM=
BBLACK= ; [ -t 1 ] && BBLACK='\033[40m'
@@ -476,20 +475,22 @@ endReturn() {
fi
}
# listProfiles [OPTION]
# listProfiles [OPTION] [SEARCH]
# List all available profiles for current user
# [OPTION]
# -q : only check for profile support
listProfiles() {
local file=
if [ $SEQ_PROFILE_SUPPORT -eq 0 ]; then
echoerr " [E] $0 does not support configuration profiles"
local profiles=()
if [[ $SEQ_CONFIG_NAME == $(basename "$SEQ_CONFIG_HOME") ]] ; then
echoerr " [E] $SEQ_NAME does not have configuration profiles"
return 1
fi
[ "$1" == "-q" ] && return 0
[[ "$1" == "-q" ]] && return 0
for file in $(ls "$SEQ_CONFIG_HOME"); do
echo ${file%.*}
[[ ${file%.*} =~ ^${1:-".*"} ]] && profiles+=(${file%.*})
done
printf '%s\n' "${profiles[*]}"
}
# initSeqConfig [OPTION] <NAME> [TEMPLATE]
@@ -531,7 +532,6 @@ initSeqConfig() {
local configLoc="$SEQ_CONFIG_HOME/$1"
if [ $seqProfiles -ne 0 ] ; then
SEQ_PROFILE_SUPPORT=1
[ -z "$SEQ_PROFILE_NAME" ] && SEQ_PROFILE_NAME=default
configLoc="$SEQ_CONFIG_HOME/$1/${SEQ_PROFILE_NAME}.cfg"
fi
@@ -1242,9 +1242,10 @@ main() {
# Cover the case when only -p is given without profile name
[ -z "$1" ] && SEQ_PROFILE_NAME=default || SEQ_PROFILE_NAME="$1"
shift;;
-pl) # List available profiles
-pl) # List available profiles with search
shift
QUIET=2
SEQ_PROFILE_LIST=1
SEQ_PROFILE_LIST="${1:-".*"}"
shift;;
--quiet|-q|-qq) # detect if option quiet is available
SEQUENCER_ARGS+=" $1"
@@ -1359,8 +1360,8 @@ main() {
fi
# Check for profile support
if [ $SEQ_PROFILE_LIST -ne 0 ]; then
listProfiles; exit $?
if [ -n "$SEQ_PROFILE_LIST" ]; then
listProfiles "${SEQ_PROFILE_LIST}"; exit $?
elif [ -n "$SEQ_PROFILE_NAME" ]; then
listProfiles -q || exit 1
fi