I am developing a custom bash
completion command to capture job IDs from a scheduling system (LSF, PBS, SLURM). I've got the basic functionality, but I would like to extend it now with "hints" that I've seen when running zsh
.
For instance when I press TAB in grep
example below, I get:
grep -<TAB>
--after-context -A -- specify lines of trailing context
--basic-regexp -G -- use basic regular expression
--before-context -B -- specify lines of leading context
...
This third column after --
is what I would like to add to my own bash
completion. What is the correct technical term for it? Hints? Does compgen
provide a functionality to do it?
I am attaching my current working example which provides IDs only. The example uses LSF.
# LSF Job ID completion
function _mycurrentjobs()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(bjobs -noheader -u $USER -o JOBID)" -- $cur))
return 0
}
complete -F _mycurrentjobs bkill bjobs bstatus bpeek bstop bresume
The command that would provide IDs and my desired hints is:
bjobs -noheader -u $USER -o "JOBID JOB_NAME"
After reviewing a similar post about host completion bash autocompletion: add description for possible completions I got the right behaviour more or less. I am using -
as a delimiter in my job id query command
function _mycurrentjobs()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local OLDIFS="$IFS"
local IFS=$'\n'
COMPREPLY=( $(compgen -W "$(bjobs -noheader -u $USER \
-o "JOBID JOB_NAME delimiter='-'")" -- $cur))
IFS="$OLDIFS"
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then #Only one completion
COMPREPLY=( ${COMPREPLY[0]%%-*} ) #Remove the separator and everything after
fi
return 0
}
complete -F _mycurrentjobs bkill bjobs bstatus bpeek bstop bresume