linux - Hints for custom bash completion -
i developing custom bash completion command capture job ids scheduling system (lsf, pbs, slurm). i've got basic functionality, extend "hints" i've seen when running zsh.
for instance when press tab in grep example below, 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 -- add own bash completion. correct technical term it? hints? compgen provide functionality it?
i attaching current working example provides ids only. 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 provide ids , desired hints is: bjobs -noheader -u $user -o "jobid job_name"
after reviewing similar post host completion bash autocompletion: add description possible completions got right behaviour more or less. using - delimiter in 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 ]]; #only 1 completion compreply=( ${compreply[0]%%-*} ) #remove separator , after fi return 0 } complete -f _mycurrentjobs bkill bjobs bstatus bpeek bstop bresume
Comments
Post a Comment