Just wondering if you actually tested this first...from what I read on the link you provided, this script fragment provided completion for the 'vault' command only if I'm understanding it correctly. In order to make this work for any command, you would have to repeat that shell fragment for _each_ command. Not sure what this gets you over just using 'complete -cf <cmd>'.
I think the author was just explaining how to create a bash completion script for an arbitrary command that could be included along with that command. Most software packages have those bash completion scripts already included. This could be used for a command that doesn't include that script already. If that's what you intended with your post it wasn't clear to me :-)
Scott
Edit: I also just noticed that without even having 'complete -cf systemctl' in my .bashrc, bash is still giving me a list of possible systemctl options when I hit <TAB> after typing systemctl. Ooo, nice! Never noticed that before
complete -cf <cmd> does not complete with flags and parameters.
I have noticed about a script called bash-completion on repos that do completion very well, I'll check it out if it works with all commands.
]]>There's a chance you have
complete -cf sudo
in your .bashrc. It's redundant because the same is already done in /usr/share/bash-completion/bash-completion, which is sourced via /etc/bash.bashrc. Comment the line out and try again.
Ahh, thanks!
I've just been avoiding zsh because I have a couple of remote shared hosting servers I interact with fairly regularly and I'm afraid of getting confused or frustrated
Scott
]]>Works better in zsh
Yes, it is the completion that really was what made me start using zsh. Though there are countless amazing things about zsh, the completion is nothing short of amazing compared to bash.
]]>because they don't work after 'sudo systemctl'.
There's a chance you have
complete -cf sudo
in your .bashrc. It's redundant because the same is already done in /usr/share/bash-completion/bash-completion, which is sourced via /etc/bash.bashrc. Comment the line out and try again.
]]>??[Veles ~]
??? sudo systemctl list-
list-dependencies list-jobs list-unit-files list-units
Works in bash for me...
??[Shiv ~ ]
??? sudo systemctl list-
list-jobs -- List jobs
list-unit-files -- List installed unit files
list-units -- List units
Works better in zsh
]]>Scott
</offtopic>
There is, alas, no silver bullet...
]]>I think the author was just explaining how to create a bash completion script for an arbitrary command that could be included along with that command. Most software packages have those bash completion scripts already included. This could be used for a command that doesn't include that script already. If that's what you intended with your post it wasn't clear to me :-)
Scott
Edit: I also just noticed that without even having 'complete -cf systemctl' in my .bashrc, bash is still giving me a list of possible systemctl options when I hit <TAB> after typing systemctl. Ooo, nice! Never noticed that before
]]>$ systemct <TAB> (this show all possible parameters/flags) and another <TAB> (show all units and itself commands).
Reading posts here and there I found that the following command in .bashrc:
complete -F or -C command
did the trick, but this is awful and painfull cause I need to implement it in all commands, such as, pacman, man, sudo, etc. Ok, googling, I found this usefull script you can put in your .bashrc:
# completion.bash
_vault_complete() {
COMPREPLY=()
local word="${COMP_WORDS[COMP_CWORD]}"
local completions="$(vault --cmplt "$word")"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
complete -f -F _vault_complete vault
This will complete all your commands with infinite posibilities. (This example use command vault, you can use whatever you want)
I put the link (well explained) here because there is a way to do it in zshell for those interested on it.
I hope this can be help someone.
Cheers
Maybe would be useful to put this script on the bashrc wiki.
]]>