Sequencer - determine system text editor and ask before seq configuration creation
This commit is contained in:
@@ -25,6 +25,8 @@ MAX_STEP=512
|
|||||||
ALIAS=
|
ALIAS=
|
||||||
CONTEXT_HELP=0
|
CONTEXT_HELP=0
|
||||||
CONTEXT_EXE=0
|
CONTEXT_EXE=0
|
||||||
|
SEQ_NAME="$_SQN_ALIAS"
|
||||||
|
[ -z "$SEQ_NAME" ] && SEQ_NAME="${0##*/}"
|
||||||
SEQ_CONFIG_EDIT=0
|
SEQ_CONFIG_EDIT=0
|
||||||
SEQ_CONFIG_NAME=".seqs"
|
SEQ_CONFIG_NAME=".seqs"
|
||||||
SEQ_CONFIG_FILE=
|
SEQ_CONFIG_FILE=
|
||||||
@@ -35,6 +37,7 @@ SEQ_PROFILE_LIST=0
|
|||||||
TEMPLATE_NAME=seqTemplateExample.sh
|
TEMPLATE_NAME=seqTemplateExample.sh
|
||||||
MISSING_CONF=missingConf.log
|
MISSING_CONF=missingConf.log
|
||||||
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
|
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
|
||||||
|
DEFAULT_EDITOR_SYSTEM=
|
||||||
|
|
||||||
BBLACK= ; [ -t 1 ] && BBLACK='\033[40m'
|
BBLACK= ; [ -t 1 ] && BBLACK='\033[40m'
|
||||||
BLACK= ; [ -t 1 ] && BLACK='\033[0;30m'
|
BLACK= ; [ -t 1 ] && BLACK='\033[0;30m'
|
||||||
@@ -59,11 +62,10 @@ SAVE_POS_EXE= ;[ -t 1 ] && SAVE_POS_EXE='\033[s'
|
|||||||
SAVE_POS= ;[ -t 1 ] && SAVE_POS='\033[3D\033[s\033[3C'
|
SAVE_POS= ;[ -t 1 ] && SAVE_POS='\033[3D\033[s\033[3C'
|
||||||
RESTORE_POS= ;[ -t 1 ] && RESTORE_POS='\033[u'
|
RESTORE_POS= ;[ -t 1 ] && RESTORE_POS='\033[u'
|
||||||
|
|
||||||
|
|
||||||
helpSequencer() {
|
helpSequencer() {
|
||||||
local scriptName=${0##*/}
|
|
||||||
[ ! -z "$_SQN_ALIAS" ] && scriptName="$_SQN_ALIAS"
|
|
||||||
cat <<USAGE_EOF
|
cat <<USAGE_EOF
|
||||||
Usage: $scriptName [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
Usage: $SEQ_NAME [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
||||||
|
|
||||||
[OPTIONS]
|
[OPTIONS]
|
||||||
--all, -a : Run all steps regardless of continuity
|
--all, -a : Run all steps regardless of continuity
|
||||||
@@ -503,6 +505,7 @@ listProfiles() {
|
|||||||
# 3 : No configuration created
|
# 3 : No configuration created
|
||||||
initSeqConfig() {
|
initSeqConfig() {
|
||||||
local arg
|
local arg
|
||||||
|
local answer
|
||||||
local sourceAlways=0
|
local sourceAlways=0
|
||||||
local createEmpty=0
|
local createEmpty=0
|
||||||
local seqProfiles=0
|
local seqProfiles=0
|
||||||
@@ -541,12 +544,25 @@ initSeqConfig() {
|
|||||||
SEQ_CONFIG_HOME="$configDir"
|
SEQ_CONFIG_HOME="$configDir"
|
||||||
|
|
||||||
if [ -s "$configLoc" ] ; then
|
if [ -s "$configLoc" ] ; then
|
||||||
[ $QUIET -ne 2 ] && echo " [I] Using configuration file: $configLoc"
|
echoseq " [I] Using configuration file: $configLoc"
|
||||||
SEQ_CONFIG_FILE="$configLoc"
|
SEQ_CONFIG_FILE="$configLoc"
|
||||||
. "$configLoc"
|
. "$configLoc"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ask for config creation if not existent
|
||||||
|
if [ $QUIET -eq 0 ] && [ $DRY -eq 0 ]; then
|
||||||
|
echo " [I] Configuration $configLoc missing"
|
||||||
|
read -p "Create it now? y/[n]? " answer
|
||||||
|
case $answer in
|
||||||
|
[yY])
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 3
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
# Config does not exist, check for template
|
# Config does not exist, check for template
|
||||||
if [ -s "$configTemplate" ] ; then
|
if [ -s "$configTemplate" ] ; then
|
||||||
|
|
||||||
@@ -558,6 +574,7 @@ initSeqConfig() {
|
|||||||
|
|
||||||
echoerr " [I] Using existing configuration: $configExists"
|
echoerr " [I] Using existing configuration: $configExists"
|
||||||
echoerr " (Moved to $configDir)"
|
echoerr " (Moved to $configDir)"
|
||||||
|
SEQ_CONFIG_FILE="$configLoc"
|
||||||
. "$configLoc"
|
. "$configLoc"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -1159,6 +1176,12 @@ exep() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Used as editor if no system editor could be found
|
||||||
|
no_editor_found() {
|
||||||
|
echoerr " [E] No editor found (\$EDITOR,\"/etc/alternatives\",nano,vi)"
|
||||||
|
echoerr " Cannot open: $*"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local arg
|
local arg
|
||||||
local START=0
|
local START=0
|
||||||
@@ -1259,17 +1282,32 @@ main() {
|
|||||||
read -p "Press enter to continue or Ctrl + C to abort"
|
read -p "Press enter to continue or Ctrl + C to abort"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Determine system default editor
|
||||||
|
DEFAULT_EDITOR_SYSTEM="$(realpath -eq "/etc/alternatives/editor")"
|
||||||
|
## Various fallbacks
|
||||||
|
[ -z "$DEFAULT_EDITOR_SYSTEM" ] && DEFAULT_EDITOR_SYSTEM="$EDITOR"
|
||||||
|
[ -z "$DEFAULT_EDITOR_SYSTEM" ] && DEFAULT_EDITOR_SYSTEM="$(command -v nano)"
|
||||||
|
[ -z "$DEFAULT_EDITOR_SYSTEM" ] && DEFAULT_EDITOR_SYSTEM="$(command -v vi)"
|
||||||
|
## Fall back to error message
|
||||||
|
[ -z "$DEFAULT_EDITOR_SYSTEM" ] && DEFAULT_EDITOR_SYSTEM="no_editor_found"
|
||||||
|
|
||||||
parseAlias
|
parseAlias
|
||||||
|
|
||||||
# run configuration for sequence only if available and if first step is valid
|
# run configuration for sequence only if available and if first step is valid
|
||||||
existsFunction step_config
|
existsFunction step_config
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
|
|
||||||
|
# Create/edit configuration file
|
||||||
if [ $SEQ_CONFIG_EDIT -ne 0 ] ; then
|
if [ $SEQ_CONFIG_EDIT -ne 0 ] ; then
|
||||||
step_config "${STEP_ARGS[@]}"
|
step_config "${STEP_ARGS[@]}"
|
||||||
[ -w "$SEQ_CONFIG_FILE" ] && vi "$SEQ_CONFIG_FILE" \
|
if [ -w "$SEQ_CONFIG_FILE" ]; then
|
||||||
|| echoerr " [E] No configuration file available"
|
"$DEFAULT_EDITOR_SYSTEM" "$SEQ_CONFIG_FILE"
|
||||||
|
else
|
||||||
|
echoerr " [E] No configuration file available"
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
checkStep "${START[0]}"
|
checkStep "${START[0]}"
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
step_config "${STEP_ARGS[@]}"
|
step_config "${STEP_ARGS[@]}"
|
||||||
|
Reference in New Issue
Block a user