Jump to content

SSH with smart hostname autocompletion


Recommended Posts

Mine is broken, too (all but 'com' should yield results with me). I cannot dig into it myself at the moment, gotta leave. Will do it tonight, if the problem is still there, then.

~/Archive/ssh$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from alfredssh import complete
>>> complete('com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "alfredssh.py", line 122, in complete
    hosts.update(fetch_ssh_config('~/.ssh/config'))
  File "alfredssh.py", line 23, in update
    (hosts, source) = _list
TypeError: 'NoneType' object is not iterable
>>> complete('mac')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "alfredssh.py", line 122, in complete
    hosts.update(fetch_ssh_config('~/.ssh/config'))
  File "alfredssh.py", line 23, in update
    (hosts, source) = _list
TypeError: 'NoneType' object is not iterable
>>> complete('net')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "alfredssh.py", line 122, in complete
    hosts.update(fetch_ssh_config('~/.ssh/config'))
  File "alfredssh.py", line 23, in update
    (hosts, source) = _list
TypeError: 'NoneType' object is not iterable

 
Link to comment

Fixed it. You weren't testing for non-existing files (I don't have an ssh_config). Couldn't resist to clean up your Linter warnings. Hope I didn't break anything. Thanks for your contribution to python-alfred!

 

http://d.pr/f/jBYw

 

Thanks, nikipore. I'd already fixed the issue via another means, but your fix is cleaner. I've integrated your tweaks, and download links/GitHub are updated.

Link to comment

Hiya.. I've got a fairly horrible .ssh/config, and no ssh_config... but it no work for me... ah, seems to be an extra 'z' on line 70:

 

 

    return (results, alias)z
 
Removing that improved things.

 

Oops. Not sure how that one slipped through. Download and source now fixed.

Link to comment

I'm trying to use this with iTerm and zsh.

 

I've set iTerm to be the default ssh:// handler, but for some reason all it's doing is opening a new terminal tab.

 

Anyone have any ideas?

 

Your iTerm ssh: handling Profile needs to specify the Command as ssh $$HOST$$ (prefix ssh with the appropriate path if you've installed a new version through MacPorts/homebrew/fink). zsh shouldn't come into it.

 

See post #8 in this thread.

Link to comment

Any way to get it to open in a tab in the existing terminal?

 

iTerm2 will do this by default, but I'm not aware of a way to get Terminal.app to do this. iTerm2 also has the advantage that it can be made to set the tab title properly (see post #8).

Link to comment

Great extension. Works like a charm.

Any chance to make it work with the "-i" argument? To ssh to those servers that need the private key file to access. That would be awesome

 

Use ~/.ssh/config (man ssh_config) to specify the private key to be used without having to type it every time.

 

Robin

Link to comment
  • 3 months later...
  • 5 weeks later...
  • 5 months later...
  • 6 months later...

This workflow isn't working for me, and I think it's because my config file is symlinked to Dropbox. When I type in `ssh` and start writing a hostname, it says "please wait" or whathaveyou for a split second before dropping me back to the standard Google prompt. Could the symlink be the issue?

Link to comment

This workflow isn't working for me, and I think it's because my config file is symlinked to Dropbox. When I type in `ssh` and start writing a hostname, it says "please wait" or whathaveyou for a split second before dropping me back to the standard Google prompt. Could the symlink be the issue?

 

This is odd. Even if you just type "ssh randomhost" it should offer to "Connect to ssh://randomhost (source: input)". That your .ssh/ssh_config is a symlink, or on Dropbox should make no difference whatsoever. Can you provide any more detail?

Link to comment

This is odd. Even if you just type "ssh randomhost" it should offer to "Connect to ssh://randomhost (source: input)". That your .ssh/ssh_config is a symlink, or on Dropbox should make no difference whatsoever. Can you provide any more detail?

 

Errr, I would, but I don't get any other errors or anything. I downloaded it from Packal, if that makes any difference. Anything in particular I can do to help debug?

Link to comment

Errr, I would, but I don't get any other errors or anything. I downloaded it from Packal, if that makes any difference. Anything in particular I can do to help debug?

 

Given you're using this workflow, I'll assume you're happy at the command line :-)

Change to the workflow's directory in Alfred preferences (found by right clicking on the Workflow and choosing "Show in Finder", if necessary), and run a query manually:

% (Pythagoras:~/Dropbox/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.E2B2A958-21D2-42ED-B6DF-06AF15C6A201) /usr/bin/python -c 'import alfredssh; print alfredssh.complete("local");'
<items><item arg="local" autocomplete="local" uid="ssh://local"><title>ssh://local</title><subtitle>Connect to ssh://local (source: input)</subtitle><icon>icon.png</icon></item><item arg="localhost" autocomplete="localhost" uid="ssh://localhost"><title>ssh://localhost</title><subtitle>Connect to ssh://localhost (source: /etc/hosts)</subtitle><icon>icon.png</icon></item><item arg="monster.local" autocomplete="monster.local" uid="ssh://monster.local"><title>ssh://monster.local</title><subtitle>Connect to ssh://monster.local (source: ~/.ssh/known_hosts)</subtitle><icon>icon.png</icon></item></items>

The output shows the workflow offering to open ssh://local (from the input provided), ssh://localhost (from /etc/hosts), ssh://monster.local (from ~/.ssh/known_hosts) when triggered with the equivalent of "ssh local" in Alfred.

If the above returns an empty list as opposed to an error or a valid list, then try running the function which parses ~/.ssh/config (which I assume is the config file you say is symlinked):

% (Pythagoras:~/Dropbox/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.E2B2A958-21D2-42ED-B6DF-06AF15C6A201) /usr/bin/python -c 'import alfredssh; print alfredssh.fetch_ssh_config("~/.ssh/config");' 
([u'host.example.com', u'monster'], '~/.ssh/ssh_config')

You should get an entry for every non-wildcard entry in your ~/.ssh/config file (host lines which include any of *, ? or ! are excluded).

NB: yes, there's currently an inconsistency. For some reason I chose to display entries from ~/.ssh/config as coming from ~/.ssh/ssh_config. Fix forthcoming.

Link to comment
user.workflow.3ACC632C-5489-45C1-92AA-6FC07DC4B472 yossarian$ python -c 'import alfredssh; print alfredssh.complete("local");'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "alfredssh.py", line 137, in complete
    fetch_known_hosts('~/.ssh/known_hosts'),
  File "alfredssh.py", line 83, in fetch_known_hosts
    results.update(line.split()[0].split(','))
IndexError: list index out of range

^^ First command - fwiw, my python version when running that command is 2.7.8. The /usr/bin version is 2.7.5 and gives me the same output.

user.workflow.3ACC632C-5489-45C1-92AA-6FC07DC4B472 yossarian$ python -c 'import alfredssh; print alfredssh.fetch_ssh_config("~/.ssh/config");'
([u'pianosa.sytes.net', u'pianosa.sytes.net/deluge', u'LiquidWeb', u'Pianosa/dreedle', u'DigitalOcean/palermo', u'DigitalOcean/napoli', u'Pianosa/crashplan'], '~/.ssh/ssh_config')

^^ Second command.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...