-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tool to generate bash/zsh completion? #24
Comments
That falls outside the realm of php and more into the realm of the shell
|
Yes, but I think it's totally possible to PHP generate the bash completion file, since the necessary definitions are already there. Completions AFAIK have four main variables:
The following template provides a very simple completion, just for commands/subcommands and options. Maybe commando could generate that, and leave to the user to create more advanced completions, if necessary. #!/usr/bin/env bash
__commando()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local first=$(echo $cur | cut -d ':' -f 1)
local second=$(echo $cur | cut -d ':' -f 2)
# Going deep on sub-commands.
case "$first" in
"subcommand")
COMPREPLY=( $( compgen -W "sub1 sub2 sub3" -- $second ) )
return 0
;;
"subcommand2")
COMPREPLY=( $( compgen -W "cmd1 cmd2 cmd3" -- $second ) )
return 0
;;
esac
# All options here
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "--all --options --here" -- $cur ) )
return 0
fi
# List of all "top" commands here.
# Subcommands should be listed on the "case" statement.
# Sub-commands are separated by ":"
COMPREPLY=( $(compgen -W "all commands here subcommand: subcommand2:" -- $cur) )
return 0
}
# zsh compatibility
if [[ -n ${ZSH_VERSION-} ]]; then
autoload -U +X bashcompinit && bashcompinit
fi
# install "complete" for session
complete -F __commando -o nospace commando-binary |
Right. It's the "leave it up to the user" part that feels funky. If it's kept isolated enough, I'm open to exploring it I suppose.
|
is there any?
The text was updated successfully, but these errors were encountered: