Skip to content

Commit

Permalink
subcommand bash completeion for gui and plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
  • Loading branch information
mabelzhang committed Apr 30, 2022
1 parent 5207d45 commit b6a97e9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions etc/ign.bash_completion.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
#!/usr/bin/env bash

# ign bash completion

function _ign
{
local prev cur cmd opts
local ign="$1"
COMPREPLY=()
cur="$2"
prev="$3"

# searching for the command
# Return value
COMPREPLY=()

# Look for the first command that is not an option (-*)
# COMP_WORDS: array of words in current command line COMP_LINE
# COMP_CWORD: index of word containing current cursur location
# COMP_LINE: line entered so far
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
cmd="${COMP_WORDS[i]}"
break
fi
done

# On a word after top-level command ign. It may be an option (-*)
if [[ "$cur" == -* ]] || [[ "$prev" != "ign" ]]; then

# Subcommand is help
if [[ "$cmd" == "help" ]]; then
opts=$(ign --commands)

# Subcommand is a library name or an option (-*)
else
COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}" ))
complete -o filenames -o nospace -F "_ign" "ign"
return
# Complete subcommands
case "$cmd" in
gui)
_ign_gui
return
;;
plugin)
_ign_plugin
return
;;
esac
fi

# on first word, top-level command (ign)
else
opts="$(ign --commands) help"
fi
Expand Down

0 comments on commit b6a97e9

Please sign in to comment.