I have read this tutorial on bash auto-completion An introduction to bash completion and I am trying to get the same auto-completion that is already done for ssh
for one of my functions (that is loaded from .profile
); which acts pretty much as an alias.
What I am trying to do is : get the same auto-completion, that is provided by default for ssh
(which is the function _known_hosts
; do complete -p | grep ssh
and you will get complete -F _known_hosts /etc/init.d/ssh
), and get it for my own function (which is installed like you woul install an alias, and that in fact does a scp
and then an ssh
with the original argument)
Command auto-completion is available when using the CLI shell. You can set up CLI command auto-completion in your operating system using the kollacli command command. This command generates a script you can save to the operating system. Copy and paste the output to a file, for example a file named /etc/bash_completion.
Bourne shell and csh do not, but ksh, bash, tcsh, and zsh all have tab completion to varying degrees. The basic principle in all of these shells is the same; you type the start of the word, hit the <TAB> key twice, and the list of possible commands or files is displayed.
Depending on your package manager, you have to manually source this file in your ~/. bashrc file. Reload your shell and verify that bash-completion is correctly installed by typing type _init_completion .
The completion function for ssh
here is _ssh
.
You can see this with complete -p ssh
(it should also have been in your grep
output) though it appears to be auto-loaded and so will not show up until after you have used it once in that session.
Anyway, that being said you should just be able to hook _ssh
up to your function as well I would think.
complete -F _ssh myfunc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With