Provide bash-completion an aliases for availale sequences including installation script
This commit is contained in:
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