Add q_completion.sh

main
Nils Gerstner 2 years ago
parent 9a5a1f3175
commit 1068a11b29

@ -8,3 +8,7 @@ Collection of scripts and functions to make my developer life easier.
**bash/sshconnect.sh**
*TUI to display a list of servers with description.*
<img src="resources/sshconnect.png" width="75%">
**bash/q_completion.sh**
*Add TAB completion to [q](https://github.com/ibm-messaging/mq-q-qload) for manipulating IBM MQ messages.*

@ -0,0 +1,63 @@
#!/bin/bash
# Author: nils gerstner
# Last revision: 09th oktober 2018
# Version: 1.1
# Description: this script enables tab complition for MQSeries Q Program by Paul Clarke.
# Instructions: to use the script you have to source it '. q_completion.sh'.
function _q_() {
# if [ -z "${PROSPECTIVE_MQSI_BASE_FILEPATH+MQSI_PROFILE_NOT_SET}" ]; then # environment is not initialized -> source profile
# echo you need to source your mqsiprofile to get completion
# return 1;
# else
QUEUEMANAGERS="$(dspmq |grep -oP "(?<=QMNAME[(])[^)]*(?=[)]\s*STATUS[(]Running[)])")"
# fi
# local cmd="${1##*/}" # gets the command that's being executed,
# this can be used if your completion function can handle multiple commands.
local line=${COMP_LINE} #The third, line, gets the entire command line that is being completed.
# local xpat='!*.foo' # The fourth variable, xpat, is our exclusion pattern,
# the same one used in the simple example above.
local word=${COMP_WORDS[COMP_CWORD]} # The second, word, gets the word that is being completed,
local prev=${COMP_WORDS[COMP_CWORD -1]} # The second, word, gets the word that is being completed,
# this can be used if your completion strategy changes based on the word that's being expanded,
# it's also needed so that only matching values are returned.
if [ ${COMP_CWORD} -eq 1 ] ; then
COMPREPLY=($(compgen -W "-m" -- ${word}))
else
case ${prev} in
-i | -I)
COMPREPLY=( $(compgen -W "$(echo "dis qlocal(*)" | \
runmqsc ${COMP_WORDS[2]} |grep -a -o -P "(?<=QUEUE[(])[^)]*"| cat )" -- ${word}) )
;;
-m)
COMPREPLY=( $(compgen -W "$(dspmq |grep -oP "(?<=QMNAME[(])[^)]*(?=[)]\s*STATUS[(]Running[)])")" -- ${word}) )
;;
-o | -O)
COMPREPLY=( $(compgen -W "$(echo "dis q(*) type" | \
runmqsc ${COMP_WORDS[2]} |grep -a -o -P "(?<=QUEUE[(])[^)]*(?=.*?TYPE[(]((QREMOTE)|(QALIAS)|(QLOCAL))[)])"| cat )" -- ${word}) )
;;
-f | -F)
COMPREPLY=($(compgen -f -- "${word}"))
;;
-M)
COMPREPLY=($(compgen -W '"test"' -- "${word}"))
;;
*)
qoptions=""
extras=""
options="-o; -O; -f; -F; -i; -I; -m; -L; -C; -gxm; -dd2; -dd3"
IFS='; ' read -r -a array <<< "${options}"
for element in "${array[@]}"; do
if [ "$(echo "$line $extras" |grep -e "${element}" )" == "" ]; then
qoptions=( "$qoptions $element " )
fi
done
COMPREPLY=($(compgen -W "${qoptions}" -- ${word}))
;;
esac
fi
}
complete -F _q_ q
Loading…
Cancel
Save