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
|
||||
```
|
||||
|
||||
## 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_REV=13
|
||||
VERSION_MAJOR=1
|
||||
VERSION_MINOR=1
|
||||
VERSION_MAJOR=2
|
||||
VERSION_MINOR=0
|
||||
|
||||
## Start of generic script part
|
||||
|
||||
@@ -65,6 +65,7 @@ Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
||||
--help, -h : Display help
|
||||
--helpapi, -ha : Display help about build-in supporting functions
|
||||
(e.g. exe,addconf,echerr,...)
|
||||
--liststeps, -ls : List all step numbers and alias
|
||||
--profile, -p : Sequence configuration profile name (default: "default")
|
||||
(if supported by sequence)
|
||||
-pl : List available profiles
|
||||
@@ -995,6 +996,38 @@ displayHelp() {
|
||||
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() {
|
||||
echo "Sequencer ${VERSION_STRING}"
|
||||
@@ -1056,6 +1089,10 @@ main() {
|
||||
--helpapi|-ha) #show build-in functions
|
||||
helpApi
|
||||
exit 0;;
|
||||
--liststeps|-ls)
|
||||
shift
|
||||
listSteps "$1"
|
||||
exit 0;;
|
||||
--profile|-p) # seq profile name
|
||||
SEQUENCER_ARGS+=" $1 $2"
|
||||
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