david-caro / wm-ssh

SSH wrapper that tries to resolve wikimedia hostnames from different sources
GNU General Public License v3.0
0 stars 1 forks source link

Add zsh completion example. #5

Open david-caro opened 2 years ago

david-caro commented 2 years ago

@blancadesal can you test this one?

blancadesal commented 2 years ago

This seems to work as long as the sought host is included inside one of the files in ~/.cache/wm-ssh/, which I think is the expected behavior. This does not include hosts inside ~/.ssh/known_hosts, or, for instance, any of the toolsbeta hosts. But maybe that has something to do with how my config is currently set up?

{
    "netbox_config_path": "~/.config/netbox/config.json",
    "known_hosts_url": "https://config-master.wikimedia.org/known_hosts.ecdsa",
    "openstack_browser_url": "https://openstack-browser.toolforge.org/api/dsh/servers",
    "netbox_config": {
        "netbox_url": "https://netbox.wikimedia.org/api",
        "api_token": "718..."
    }
}
blancadesal commented 2 years ago

Just realized I had left the source "~/wm-ssh/utils/wm-ssh.complete in my ~/.zshrc. If I comment it out, things stop working.

[~] wm-ssh clo(anon):4: command not found: _wm_ssh

david-caro commented 2 years ago

Did you restart the shell? (exec zsh or similar)

blancadesal commented 2 years ago

Did you restart the shell? (exec zsh or similar)

Yes

david-caro commented 2 years ago

Hmm... this script works for me:

[dcaro@magnum]~% wm-ssh <tab><tab>
zsh: do you wish to see all 2063 possibilities (344 lines)?
...
cloudvirt1045.eqiad.wmnet                   dns3002.wikimedia.org                       kubemaster1001.eqiad.wmnet                  ms-fe2010.codfw.wmnet                       mw2419.codfw.wmnet                          zookeeper-test1002.eqiad.wmnet
cloudvirt1046.eqiad.wmnet                   dns4001.wikimedia.org                       kubemaster1002.eqiad.wmnet                  ms-fe2011.codfw.wmnet                       mwdebug1001.eqiad.wmnet

And this is all I have:

[dcaro@magnum]~% cat .zshrc
fpath=($HOME/.zsh_completions $fpath)

autoload -U compinit
compinit
[dcaro@magnum]~% cat .zsh_completions/_wm-ssh.zsh
#compdef wm-ssh

hosts=($(cat ~/.cache/wm-ssh/*))

_describe 'command' hosts
[dcaro@magnum]~% zsh --version
zsh 5.8.1 (x86_64-redhat-linux-gnu)
david-caro commented 2 years ago

[~] wm-ssh clo(anon):4: command not found: _wm_ssh

The command not found _wm_ssh is suspicious, there's nothing in the script that names the command _wm_ssh (two underscores), maybe some leftover tests somewhere?