Skip to content

Instantly share code, notes, and snippets.

@daimor
Last active August 19, 2021 04:56
Show Gist options
  • Save daimor/3a831b7af86d8418f366 to your computer and use it in GitHub Desktop.
Save daimor/3a831b7af86d8418f366 to your computer and use it in GitHub Desktop.
bash completions for InterSystems cache
#!/bin/bash
# bash completions for InterSystems ccontrol
_instances()
{
if [ $# == 0 ] || [ $1 == "all" ]; then
echo $(ccontrol qlist | cut -d'^' -f1 | tr '\n' ' ')
else
echo $(ccontrol qlist | grep "\^$1\," | cut -d'^' -f1 | tr '\n' ' ')
fi
}
_ccontrol()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
commands="start stop force backup stat create update delete rename default view list qlist all qall nodename session version help"
if [[ ${COMP_CWORD} == 1 ]] ; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
fi
command="${COMP_WORDS[1]}"
parameters=""
case "${command}" in
start)
instances=$(_instances down)
parameters="quietly nostu help"
;;
stop)
instances=$(_instances running)
parameters="quietly nouser bypass restart nofailover help"
;;
force)
instances=$(_instances running)
parameters="quietly help"
;;
backup)
instances=$(_instances running)
parameters="quietly help"
;;
stat)
instances=$(_instances running)
parameters="-h -? "
;;
create)
instances="NEWINSTANCE"
parameters="directory= versionid="
;;
update)
instances=$(_instances all)
parameters="versionid="
;;
delete)
instances=$(_instances all)
parameters=""
;;
rename)
instances=$(_instances all)
parameters="NEWNAME"
;;
default)
instances=$(_instances all)
;;
view)
instances=$(_instances all)
;;
list)
instances=$(_instances all)
;;
qlist)
instances=$(_instances all)
;;
session)
instances=$(_instances running)
parameters="-B -U -b"
if [[ ${COMP_CWORD} > 3 ]] && [[ ${COMP_WORDS[COMP_CWORD-1]} == "-U" ]] ; then
namespaces="USER SAMPLES %SYS"
COMPREPLY=( $(compgen -W "${namespaces^^}" -- ${cur^^}) )
return 0
fi
;;
help)
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}))
return 0
;;
*)
return 0
;;
esac
if [[ ${COMP_CWORD} == 2 ]] ; then
COMPREPLY=( $(compgen -W "${instances^^}" -- ${cur^^}))
fi
if [[ ${parameters} == "" ]] ; then
return 0
fi
if [[ ${COMP_CWORD} > 2 ]]; then
COMPREPLY=( $(compgen -W "${parameters}" -- ${cur}) )
fi
return 0
}
complete -F _ccontrol ccontrol
#!/bin/bash
# bash completions for InterSystems csession
_csession()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ ${COMP_CWORD} == 1 ]] ; then
instances=`ccontrol qlist | grep running | cut -d'^' -f1 | tr '\n' ' '`
COMPREPLY=( $(compgen -W "${instances^^}" -- ${cur^^}) )
return 0
fi
if [[ ${COMP_CWORD} == 2 ]] ; then
parameters="-B -U -b"
COMPREPLY=( $(compgen -W "${parameters}" -- ${cur}) )
return 0
fi
if [[ ${COMP_CWORD} == 3 ]] ; then
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ ${prev} == "-U" ]] ; then
namespaces="USER SAMPLES %SYS"
COMPREPLY=( $(compgen -W "${namespaces^^}" -- ${cur^^}) )
return 0
fi
return 0
fi
}
complete -F _csession csession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment