Files
OpenUxAS-bootstrap/install/run-example-completion.bash
M. Anthony Aiello 79808e93c4 Provide autocompletion for run-example (#64)
Users will have to load this into their shell by sourcing the file,
either directly (at the command line) or in their .bashrc, like this:

	source /path/to/bootstrap/install/run-example-completion.bash

Then tab completion will show the output of --list in run-example.

Note that --list isn't actually entirely well-suited for this, so there
is extra garbage that is offered. A change would be needed to
run-example to give it a mode specifically for completion. This does
work, at present.

This also works for zsh.
2020-07-24 10:26:14 -04:00

18 lines
578 B
Bash

#! /usr/bin/env bash
# This completion works for zsh (even though the script says "bash" in the
# file extension), but we have to find the script directory differently.
if [ $ZSH_VERSION ]; then
INSTALL_DIR=${0:a:h}
else
# Assume bash. (Could test with $BASH_VERSION, but we don't have a fallback
# plan.)
INSTALL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
fi
_run_example_completions() {
COMPREPLY=( $( compgen -W "$( ${INSTALL_DIR}/../run-example --list )" -- "${COMP_WORDS[1]}" ) )
}
complete -F _run_example_completions run-example