You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.8 KiB
64 lines
2.8 KiB
2 years ago
|
#!/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
|