assh icon indicating copy to clipboard operation
assh copied to clipboard

zsh host autocompletion

Open ivomarino opened this issue 8 years ago • 12 comments

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

ivomarino avatar Nov 08 '16 22:11 ivomarino

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)

ocean90 avatar Nov 09 '16 15:11 ocean90

great one, will test it, thanks @ocean90.

ivomarino avatar Nov 09 '16 16:11 ivomarino

I just added

  assh wrapper ssh
}

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

cnf avatar Jan 03 '17 16:01 cnf

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.

Falkor avatar Mar 12 '17 12:03 Falkor

@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.

ocean90 avatar Mar 14 '17 09:03 ocean90

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.

Falkor avatar Mar 14 '17 10:03 Falkor

@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.

ocean90 avatar Mar 14 '17 11:03 ocean90

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.

austinbutler avatar Mar 14 '17 16:03 austinbutler

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

Falkor avatar Mar 16 '17 14:03 Falkor

@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 avatar Mar 16 '17 20:03 ocean90

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

ocean90 avatar Mar 16 '17 20:03 ocean90

Excellent, I'll update my own accordingly

Falkor avatar Mar 17 '17 08:03 Falkor