muxed
muxed copied to clipboard
Investigate bash auto-completion
We want two types of auto complete:
- Auto complete muxed commands (only new)
- Auto complete project names
#/usr/bin/env bash
_muxed_completions()
{
if [ "$COMP_CWORD" -eq 1 ]; then
local commands="$(compgen -W "new edit snapshot" "${COMP_WORDS[1]}")"
local projects="$(compgen -W "$(echo $(ls ~/.muxed/))" "${COMP_WORDS[1]}")"
COMPREPLY=( $commands $projects )
elif [ "$COMP_CWORD" -eq 2 ]; then
local projects="$(compgen -W "$(echo $(ls ~/.muxed/))" "${COMP_WORDS[2]}")"
COMPREPLY=( $projects )
fi
}
complete -F _muxed_completions muxed
A simple first pass.
It'll auto complete subcommands, and projects available in the default directory only.
Expand it to autocomplete projects but stripping the .yml (extension) in the filename.
Have it complete in custom directories.
With the ls subcommand this has gotten a bit simpler. Here is my current config
#/usr/bin/env bash
_muxed_completions()
{
if [ "$COMP_CWORD" -eq 1 ]; then
local commands="$(compgen -W "new edit snapshot load" "${COMP_WORDS[1]}")"
local projects="$(compgen -W "$(muxed ls)" "${COMP_WORDS[1]}")"
COMPREPLY=( $commands $projects )
elif [ "$COMP_CWORD" -eq 2 ]; then
local projects="$(compgen -W "$(muxed ls)" "${COMP_WORDS[2]}")"
COMPREPLY=( $projects )
fi
}
complete -F _muxed_completions muxed