moul / assh

:computer: make your ssh client smarter
https://manfred.life/assh
MIT License
3.06k stars 156 forks source link

zsh host autocompletion #180

Open ivomarino opened 8 years ago

ivomarino commented 8 years ago

As in topic, is this actually working for someone? We're on oh-my-zsh here, thanks for info.

ocean90 commented 8 years ago

Here's an initial version of a plugin which adds zsh completion for options and for SSH hosts: https://gist.github.com/ocean90/3e5da3c526c66144eab3a78b0101b2ec

Copy the file into ~/.oh-my-zsh/plugins/assh/_assh and add assh to the plugins list in your ~/.zshrc file.

➜  ~ ssh .wp.dev[tab]
37.wp.dev           41.wp.dev           45.wp.dev           build.wpmu.dev      git.wp.dev
38.wp.dev           42.wp.dev           46.wp.dev           develop.wp.dev      glotpress.wp.dev
39.wp.dev           43.wp.dev           build.wp.dev        develop.wphhvm.dev  shared.wp.dev
40.wp.dev           44.wp.dev           build.wphhvm.dev    develop.wpmu.dev

➜  ~ assh -[tab]
--config   -c  -- location of config file
--debug    -D  -- debug mode
--help     -h  -- show help
--verbose  -V  -- verbose mode
--version  -v  -- print the version

To do: Add support for the commands (info, config, sockets)

ivomarino commented 8 years ago

great one, will test it, thanks @ocean90.

cnf commented 7 years ago

I just added

  assh wrapper ssh
}

to my zshrc and it works as is for ssh hosts.

Falkor commented 7 years ago

Another version: Falkor ZSH completion file _assh to handle the commands of assh. For host completion, as indicated by @cnf , it is sufficient to add the wrapper with ssh.

ocean90 commented 7 years ago

@Falkor Thanks, works like a charm! Could you please elaborate on the host completion part? Where do I have to add the line which @cnf has posted? I'm confused by the closing bracket there. Any help would be appreciated.

Edit: To get host completion working with you file I had to change '*:: :->options' && ret=0 to '*:host:_hosts' && return 0.

Falkor commented 7 years ago

If you remove the options line, then you never enter the case ... (options) ... esac part with permit to have completion also on the subcommands ;) I do not see how to properly integrate host completion at this level (actually, I personally don't see it as critical) thus the wrapper command suggested by @cnf is probably sufficient. Not sure however how it is compliant with any completion file -- I'm not enough advanced with zsh to know it.

ocean90 commented 7 years ago

@Falkor The question is, what is this wrapper command you're talking about? :) I already have alias ssh="assh wrapper ssh" in my zshrc file so I guess it must be something else.

austinbutler commented 7 years ago

Strangely for me simply having the wrapper worked fine for host completion when I first started messing with assh, probably when the config was simpler. Now though I get no host completion at all.

Falkor commented 7 years ago

@ocean90 I updated my completion file to include host completion upon assh [...] connect <tab> -- see _assh line 51

ocean90 commented 7 years ago

@Falkor Thanks, but I want to have it for the regular ssh command/alias. I guess we'd have to do the same for assh wrapper ssh <tab>?

$ assh wrapper
NAME:
   assh wrapper - Initialize assh, then run ssh/scp/rsync...

USAGE:
   assh wrapper command [command options] [arguments...]

COMMANDS:
     ssh  Wrap ssh

OPTIONS:
   --help, -h  show help
ocean90 commented 7 years ago

@Falkor This is working for me: https://gist.github.com/ocean90/31371768e6b6f47e06feb3ba34906361/revisions#diff-918a0e7065f6765a4de05d48967c1347

Falkor commented 7 years ago

Excellent, I'll update my own accordingly