0

I needed to get the fingerprint of a ssh key using:

$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub

after typing:ssh-keygen -lf ~/.ss TAB It was not giving any options.

I had to do:

$ compdef _files ssh-keygen

After that I was available to autocomplete using the files path, but the command autocomplete stop working, so if if I type ssh-keygen - Tab I don't see any more this output:

$ ssh-keygen -
 -- option --
-B  -- show the bubblebabble digest of key
-C  -- provide new comment
-D  -- download key stored in smartcard reader
-N  -- provide new passphrase
-P  -- provide old passphrase
-U  -- upload key to smartcard reader
-b  -- specify number of bits in key
-c  -- change comment in private and public key files
-e  -- export key to SECSH file format
-f  -- key file
-i  -- import key to OpenSSH format
-l  -- show fingerprint of key file
-p  -- change passphrase of private key file
-q  -- silence ssh-keygen
-t  -- specify the type of the key to create
-y  -- get public key from private key

So wondering if there is a way of having both options enabled so that I can do something like:

ssh-keyg TAB that will give me:

$ ssh-keygen

Then I can do

$ ssh-keygen - TAB

That would print the option menu and been available to do:

$ ssh-keygen -lf ~/.ss TAB

And have list of options what could work so at the end I would get something like:

$ ssh-keygen -lf ~/.ssh/id_rsa_user.pub

For now I just add to my ~/.zshrc this:

compdef _files ssh-keygen
compdef _files adb
compdef _files mysql
...

But I have to do that for avery command I want to use the _files completion, therefore I would like to know if there is a way to always use _files or failover to it.

Any ideas?

Could it be possible to make it behave like csh in where pressing Ctrl+d shows files options?

Update:

I notice that if I the last argument is an -f the autocomplete works:

ssh-keygen -l -f ~/.sshTAB

But for custom scripts, commands what function, widget alias could help do force the _files completion.?

nbari
  • 25,603
  • 10
  • 76
  • 131
  • "Could it be possible to make it behave like csh in where pressing Ctrl+d shows files options?" - I think you can achieve this using the example given in the [zsh docs for completion widgets](http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html#Completion-Widget-Example-1) – Nils Luxton Apr 18 '16 at 11:30
  • I know this doesn't necessarily help you, but what you're after with ssh-keygen is exactly how my zsh behaves, so it's definitely possible. ssh-keygen -lf ~/.ssh gives me a files completion list. – Nils Luxton Apr 18 '16 at 11:34
  • @NilsLuxton Hi, you can both get options ``ssh-keygen -``TAB and also get files when doing ``ssh-keygen -lt ~/.s`` TAB, if yes could you please tell me how you are doing it. – nbari Apr 18 '16 at 12:11
  • Yes, that's right, but I don't know enough about how it all works to be able to tell you how to do it I'm afraid...sorry! – Nils Luxton Apr 18 '16 at 12:27
  • if you come back on IRC at #zsh we can try and figure it out together - I've found something I think – Nils Luxton Apr 18 '16 at 12:30

1 Answers1

0

The solution was to update to zsh this is how I did it:

# check the zsh info
brew info zsh

# install zsh
brew install zsh

# add shell path
sudo vim /etc/shells

# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh

# change default shell
chsh -s /usr/local/bin/zsh

I had issues completing git-flow this was fixed by reinstalling with --without-completions:

$ brew install git --without-completions
nbari
  • 25,603
  • 10
  • 76
  • 131