You are not logged in.
I was searching for a tab completion in systemd commands such as:
$ 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.
Last edited by JohnnyDeacon (2013-05-21 13:21:21)
Offline
I realize this is not your script, but I am going to move this to community contributions where others are more likely to look for a script as such.
Last edited by ewaller (2013-05-16 02:00:02)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Of course this is not my script but I found it very useful.
Offline
As to the Wiki: Heck, it is a wiki.... have at it.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
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
Last edited by firecat53 (2013-05-16 02:50:44)
Offline
Yes, Scott is right. If you have bash_completion installed, you can look through /usr/share/bash-completion/completions to see how these hooks are written for all of the different commands.
There is, alas, no silver bullet...
Offline
<offtopic>
Ahh, I know why I haven't noticed the systemctl completions before...because they don't work after 'sudo systemctl'. Only after 'systemctl'. Grrrr. Any idea how to fix that?
Scott
</offtopic>
Offline
??[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
Offline
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.
:: Registered Linux User No. 223384
:: github
:: infinality-bundle+fonts: good looking fonts made easy
Offline
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.
Offline
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
Offline
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.
Offline
Unless I misunderstood something, getting bash-completion (it's in the official repo) does this for all commands.
Offline