Provide bash-completion an aliases for availale sequences including installation script
This commit is contained in:
23
README.md
23
README.md
@@ -37,3 +37,26 @@ use the simple bash installation script in the repository:
|
|||||||
```
|
```
|
||||||
curl -L https://winklerfamilie.eu/git/efelon/shell_sequencer/raw/branch/master/install.sh | bash
|
curl -L https://winklerfamilie.eu/git/efelon/shell_sequencer/raw/branch/master/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Bash-completion
|
||||||
|
|
||||||
|
The included optional bash-completion script `sqnall-completion.bash` provides aliases to all available sequences as well as completion for sequencer.sh options and steps (including aliases) individually for each sequence. The aliases have the prefix `sqn_` which stands for _sequence name_.
|
||||||
|
|
||||||
|
After executing
|
||||||
|
|
||||||
|
```
|
||||||
|
source /opt/sequencer/sqnall-completion.bash
|
||||||
|
```
|
||||||
|
|
||||||
|
e.g. `/opt/sequencer/seqs/kodi.sh` can be started anyhere with `sqn_kodi`
|
||||||
|
|
||||||
|
|
||||||
|
### Automatic setup after login
|
||||||
|
|
||||||
|
To automatically provide aliases and bash-completion after login, the following bash script needs to be executed once for each user separately:
|
||||||
|
|
||||||
|
```
|
||||||
|
source /opt/sequencer/installCompletion.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This sources the bash-completion script in the users .bashrc file.
|
||||||
|
20
installCompletion.sh
Executable file
20
installCompletion.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sequencerCompletion() {
|
||||||
|
local SEQBASE="/opt/sequencer"
|
||||||
|
local SEQCOMP_LOC="$SEQBASE/sqnall-completion.bash"
|
||||||
|
local SEQCOMP_LOADER="$(realpath ~/.bashrc)"
|
||||||
|
local SEQCOMP_SOURCE="source \"$SEQCOMP_LOC\""
|
||||||
|
|
||||||
|
grep "$SEQCOMP_SOURCE" "$SEQCOMP_LOADER" >>/dev/null 2>&1
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo " [I] Completion already installed ($SEQCOMP_LOADER)"
|
||||||
|
else
|
||||||
|
echo "$SEQCOMP_SOURCE" >>"$SEQCOMP_LOADER"
|
||||||
|
[ $? -eq 0 ] && echo " [I] Sequence bash-completion installed"
|
||||||
|
fi
|
||||||
|
source "$SEQCOMP_LOC"
|
||||||
|
}
|
||||||
|
|
||||||
|
sequencerCompletion
|
||||||
|
|
@@ -8,8 +8,8 @@
|
|||||||
## Version information
|
## Version information
|
||||||
|
|
||||||
VERSION_REV=13
|
VERSION_REV=13
|
||||||
VERSION_MAJOR=1
|
VERSION_MAJOR=2
|
||||||
VERSION_MINOR=1
|
VERSION_MINOR=0
|
||||||
|
|
||||||
## Start of generic script part
|
## Start of generic script part
|
||||||
|
|
||||||
@@ -59,23 +59,24 @@ helpSequencer() {
|
|||||||
Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
||||||
|
|
||||||
[OPTIONS]
|
[OPTIONS]
|
||||||
--config, -c : Open sequence configuration file (also sets -qq)
|
--config, -c : Open sequence configuration file (also sets -qq)
|
||||||
--dry-run, -d : Only print to console what would be done
|
--dry-run, -d : Only print to console what would be done
|
||||||
! Attention - Sequence must support this
|
! Attention - Sequence must support this
|
||||||
--help, -h : Display help
|
--help, -h : Display help
|
||||||
--helpapi, -ha : Display help about build-in supporting functions
|
--helpapi, -ha : Display help about build-in supporting functions
|
||||||
(e.g. exe,addconf,echerr,...)
|
(e.g. exe,addconf,echerr,...)
|
||||||
--profile, -p : Sequence configuration profile name (default: "default")
|
--liststeps, -ls : List all step numbers and alias
|
||||||
(if supported by sequence)
|
--profile, -p : Sequence configuration profile name (default: "default")
|
||||||
-pl : List available profiles
|
(if supported by sequence)
|
||||||
--quiet, -q : Don't ask for permission to execute steps
|
-pl : List available profiles
|
||||||
If called without starting step number, only this help is shown
|
--quiet, -q : Don't ask for permission to execute steps
|
||||||
-qq : Same as --quiet but suppresses regular sequencer.sh output
|
If called without starting step number, only this help is shown
|
||||||
--single, -s : Execute only one step
|
-qq : Same as --quiet but suppresses regular sequencer.sh output
|
||||||
If more than one step is requested, only the first will be executed
|
--single, -s : Execute only one step
|
||||||
--verbose, -v : Verbose output (use exe() function to call shell commands in seqs)
|
If more than one step is requested, only the first will be executed
|
||||||
( e.g.: exe apt update )
|
--verbose, -v : Verbose output (use exe() function to call shell commands in seqs)
|
||||||
--version : Display version of sequencer and revision of sequence
|
( e.g.: exe apt update )
|
||||||
|
--version : Display version of sequencer and revision of sequence
|
||||||
|
|
||||||
[STEP NUMBER"(s)" 1-${MAX_STEP} or ALIAS]
|
[STEP NUMBER"(s)" 1-${MAX_STEP} or ALIAS]
|
||||||
No STEP or ALIAS : assume 1 as starting point
|
No STEP or ALIAS : assume 1 as starting point
|
||||||
@@ -995,6 +996,38 @@ displayHelp() {
|
|||||||
CONTEXT_HELP=0
|
CONTEXT_HELP=0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# listSteps [FILTER STRING]
|
||||||
|
# [FILTER STRING]
|
||||||
|
# show only steps and aliases starting with [FILTER STRING]
|
||||||
|
listSteps() {
|
||||||
|
local aList=()
|
||||||
|
local aSearch="$1"
|
||||||
|
local locAlias=
|
||||||
|
|
||||||
|
for ((i=1; i<=${MAX_STEP}; i++)); do
|
||||||
|
# Display step reference in help if step function exists
|
||||||
|
existsFunction step_${i}
|
||||||
|
[ $? -ne 0 ] && continue
|
||||||
|
|
||||||
|
# Display alias if exists
|
||||||
|
existsFunction step_${i}_alias
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
step_${i}_alias
|
||||||
|
locAlias=("$ALIAS")
|
||||||
|
else
|
||||||
|
locAlias=("$i")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$aSearch" ]; then
|
||||||
|
aList+=("$locAlias")
|
||||||
|
elif [[ "$locAlias" =~ ^$aSearch ]]; then
|
||||||
|
aList+=("$locAlias")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
[ ${#aList[@]} -ne 0 ] && echo "${aList[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
# showVersion
|
# showVersion
|
||||||
showVersion() {
|
showVersion() {
|
||||||
echo "Sequencer ${VERSION_STRING}"
|
echo "Sequencer ${VERSION_STRING}"
|
||||||
@@ -1056,6 +1089,10 @@ main() {
|
|||||||
--helpapi|-ha) #show build-in functions
|
--helpapi|-ha) #show build-in functions
|
||||||
helpApi
|
helpApi
|
||||||
exit 0;;
|
exit 0;;
|
||||||
|
--liststeps|-ls)
|
||||||
|
shift
|
||||||
|
listSteps "$1"
|
||||||
|
exit 0;;
|
||||||
--profile|-p) # seq profile name
|
--profile|-p) # seq profile name
|
||||||
SEQUENCER_ARGS+=" $1 $2"
|
SEQUENCER_ARGS+=" $1 $2"
|
||||||
shift
|
shift
|
||||||
|
40
sqnall-completion.bash
Executable file
40
sqnall-completion.bash
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
_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")"
|
||||||
|
curCmd="${curCmd#*=\'}"
|
||||||
|
curCmd="${curCmd%\'*}"
|
||||||
|
COMPREPLY=()
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W '-c -d -h -ha -ls -p -pl -q -qq -s -v --version' -- $cur ) );;
|
||||||
|
*)
|
||||||
|
# Stop after step selection (last argument which is not an option; starting with "-")
|
||||||
|
(( COMP_CWORD > 1 )) && [[ ! "${COMP_WORDS[((COMP_CWORD - 1))]}" =~ ^- ]] && return
|
||||||
|
# sequencer.sh provides creation of a step list with search functionality
|
||||||
|
COMPREPLY=( $( "$curCmd" -ls "$cur" ) );;
|
||||||
|
esac
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
installCompletion() {
|
||||||
|
local SEQBASE="/opt/sequencer/seqs"
|
||||||
|
local SEQPREFIX="sqn_"
|
||||||
|
local SEQSHORT=()
|
||||||
|
# Create aliases and command (alias) list for "complete" command"
|
||||||
|
SEQLIST=($(ls "$SEQBASE/$cur"*.sh))
|
||||||
|
for i in "${!SEQLIST[@]}"; do
|
||||||
|
SEQLIST[$i]="${SEQLIST[$i]##*/}"
|
||||||
|
SEQLIST[$i]="${SEQLIST[$i]%.*}"
|
||||||
|
SEQSHORT[$i]="${SEQPREFIX}${SEQLIST[$i]}"
|
||||||
|
alias ${SEQSHORT[$i]}="$SEQBASE/${SEQLIST[$i]}.sh"
|
||||||
|
done
|
||||||
|
complete -o nosort -o bashdefault -o default -F _sqnall_completions ${SEQSHORT[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
installCompletion
|
Reference in New Issue
Block a user