Skip to content

Commit 80f7cc2

Browse files
committed
Option to use SSH shell command instead of URL #8
- Add in-workflow configuration - Update awgo & docopt - Fix build script
1 parent b076d1e commit 80f7cc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+983
-546
lines changed

.gitignore

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,9 @@
1-
# Keep the generated binary out of the repo
2-
/assh
1+
2+
# Build artefacts
33
/build
44
/dist
55

6-
# Local env
7-
.autoenv.zsh
8-
.autoenv_leave.zsh
9-
10-
11-
# Created by https://www.gitignore.io/api/vim,go
12-
13-
### Vim ###
14-
# swap
15-
[._]*.s[a-w][a-z]
16-
[._]s[a-w][a-z]
17-
# session
18-
Session.vim
19-
# temporary
20-
.netrwhist
21-
*~
22-
# auto-generated tag files
23-
tags
24-
25-
### Go ###
26-
# Compiled Object files, Static and Dynamic libs (Shared Objects)
27-
*.o
28-
*.a
29-
*.so
30-
31-
# Folders
32-
_obj
33-
_test
34-
35-
# Architecture specific extensions/prefixes
36-
*.[568vq]
37-
[568vq].out
38-
39-
*.cgo1.go
40-
*.cgo2.c
41-
_cgo_defun.c
42-
_cgo_gotypes.go
43-
_cgo_export.*
44-
45-
_testmain.go
46-
47-
*.exe
48-
*.test
49-
*.prof
6+
# Vendoring
7+
/vendor/*
8+
Gopkg.lock
509

51-
*.tags
52-
*tags1

Gopkg.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Gopkg.toml example
3+
#
4+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5+
# for detailed Gopkg.toml documentation.
6+
#
7+
# required = ["github.com/user/thing/cmd/thing"]
8+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9+
#
10+
# [[constraint]]
11+
# name = "github.com/user/project"
12+
# version = "1.0.0"
13+
#
14+
# [[constraint]]
15+
# name = "github.com/user/project2"
16+
# branch = "dev"
17+
# source = "github.com/myfork/project2"
18+
#
19+
# [[override]]
20+
# name = "github.com/x/y"
21+
# version = "2.4.0"
22+
23+
24+
[[constraint]]
25+
branch = "master"
26+
name = "github.com/danieljimenez/ssh_config"
27+
28+
[[constraint]]
29+
name = "github.com/deanishe/awgo"
30+
branch = "v0.14"
31+
32+
[[constraint]]
33+
name = "github.com/docopt/docopt-go"
34+
branch = "master"
35+

README.md

Lines changed: 125 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,129 +5,186 @@ Open SSH/SFTP/mosh connections from [Alfred 3][alfredapp] with autosuggestions b
55

66
!["Secure SHell Demo"][demo]
77

8+
<!-- MarkdownTOC autolink="true" bracket="round" depth="3" autoanchor="true" -->
89

10+
- [Features](#features)
11+
- [Installation](#installation)
12+
- [Usage](#usage)
13+
- [Configuration](#configuration)
14+
- [Sources](#sources)
15+
- [Advanced configuration](#advanced-configuration)
16+
- [Using iTerm2](#using-iterm2)
17+
- [Licensing & thanks](#licensing--thanks)
18+
- [Changelog](#changelog)
19+
20+
<!-- /MarkdownTOC -->
21+
22+
<a id="features"></a>
923
Features
1024
--------
1125

12-
- Auto-suggest hostnames from `~/.ssh/*` and `/etc/hosts` (sources can be individually disabled).
13-
- Remembers usernames, so you don't have to type them in every time. (You can also remove connections from your history or disable it entirely.)
26+
- Auto-suggest hostnames
27+
- Remembers usernames, so you don't have to type them in every time
1428
- Alternate actions:
15-
- Open connection with mosh instead of SSH.
16-
- Open SFTP connection instead of SSH.
17-
- Ping host.
18-
19-
20-
### Data sources
21-
22-
The workflow reads hosts from the following sources (in this order of priority):
23-
24-
1. `~/.ssh/config`
25-
2. History (i.e. username + host addresses previously entered by the user)
26-
3. `~/.ssh/known_hosts`
27-
4. `/etc/hosts`
28-
5. `/etc/ssh/ssh_config`
29-
30-
29+
- Open connection with **mosh**
30+
- Open **SFTP** connection
31+
- **Ping** host
32+
- Sources (can be managed individually):
33+
- `~/.ssh/config`
34+
- `~/.ssh/known_hosts`
35+
- History (i.e. username + host addresses previously entered by the user)
36+
- `/etc/hosts`
37+
- `/etc/ssh/ssh_config`
38+
39+
40+
<a id="installation"></a>
3141
Installation
3242
------------
3343

3444
Download [the latest release][gh-releases] and double-click the file to install in Alfred.
3545

3646

47+
<a id="usage"></a>
3748
Usage
3849
-----
3950

40-
Keyword is `ssh`:
51+
The main keyword is `ssh`:
4152

4253
- `ssh [<query>]` — View and filter known SSH connections.
4354

44-
- `` or `⌘+<NUM>` — Open the connection.
45-
- `` — Expand query to selected connection's title. Useful for adding a port number.
46-
- `⌘+↩` — Open an SFTP connection instead.
47-
- `⌘+⌥` — Open a mosh connection instead.
48-
- `⇧+↩` — Ping host.
49-
- `^+↩` — Forget connection (if it's from history).
55+
- `` or `⌘+<NUM>` — Open the connection.
56+
- `` — Expand query to selected connection's title. Useful for adding a port number.
57+
- `⌘+↩` — Open an SFTP connection instead.
58+
- `⌥+↩` — Open a mosh connection instead.
59+
- `⇧+↩` — Ping host.
60+
- `^+↩` — Forget connection (if it's from history).
61+
62+
Configuration is managed with `sshconf`:
63+
64+
- `sshconf [<query>]` — Edit workflow settings (see [Configuration](#configuration))
65+
- `An Update is Available!` or `Workflow is Up to Date` — Action to check for an update and install if one is available.
66+
- `Source: XYZ` — Toggle source on/off
67+
- `Log File` — Open workflow's log file in the default app (usually Console.app)
68+
- `Documentation` / `Report Issue` / `Visit Forum` — Open docs, issue tracker or forum thread in your browser.
69+
70+
71+
<a id="configuration"></a>
72+
### Configuration ###
73+
74+
Sources can be configured from within the workflow using the `sshconf` keyword. Other settings are managed via the [workflow's configuration sheet][confsheet].
75+
5076

77+
<a id="sources"></a>
78+
#### Sources ####
5179

52-
### Configuration
80+
The following sources are available and can be toggled on/off using `sshconf`:
5381

54-
There are several options available in the workflow's configuration sheet. Notably, you can turn off individual autosuggestion sources.
82+
| Name | Source |
83+
|-------------------------|------------------------|
84+
| **SSH Config** | `~/.ssh/config` |
85+
| **SSH Config (system)** | `/etc/ssh/ssh_config` |
86+
| **/etc/hosts** | `/etc/hosts` |
87+
| **History** | User-entered hostnames |
88+
| **Known Hosts** | `~/.ssh/known_hosts` |
5589

56-
| Variable | Description |
57-
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
58-
| `DISABLE_CONFIG` | Set to `1` to turn off suggestions from `~/.ssh/config`. |
59-
| `DISABLE_ETC_CONFIG` | Set to `1` to turn off suggestions from `/etc/ssh/ssh_config`. |
60-
| `DISABLE_ETC_HOSTS` | Set to `1` to turn off suggestions from `/etc/hosts`. |
61-
| `DISABLE_HISTORY` | Set to `1` to disable the History (reading and writing). |
62-
| `DISABLE_KNOWN_HOSTS` | Set to `1` to turn off suggestions from `~/.ssh/known_hosts`. |
63-
| `EXIT_ON_SUCCESS` | Set to `1` (default) to close shell if `ping` or `mosh` command exits cleanly |
64-
| `EXTERNAL_TRIGGER` | Set to `1` to use an External Trigger instead of AppleScript to re-open Alfred. The External Trigger is safer, but leaves Alfred in a weird mode. |
65-
| `MOSH_CMD` | Set to the full path to `mosh` if your shell can't find it. Set to empty to disable `mosh` connections. |
6690

67-
<!--
68-
**Please note**: The workflow generates an `ssh://` (or `sftp://`) URL and asks Alfred to open it. Similarly, the `ping` and `mosh` features uses Alfred 3's Terminal Command feature. If it's not opening in the right app, it's not the workflow's fault.
69-
-->
91+
<a id="advanced-configuration"></a>
92+
#### Advanced configuration ####
7093

71-
For SSH and SFTP connections, the workflow creates an `ssh://` (or `sftp://`) URL and asks the system to open it. These will open in whichever application you have configured to handle these URLs (Terminal.app is the default for `ssh://`).
94+
There are several additional settings that can only be edited via the [workflow's configuration sheet][confsheet], which allow you to specify a few commands and applications.
7295

73-
The `ping` and `mosh` commands use Alfred's [Terminal Command][alfterm] output, which also call Terminal.app by default.
96+
To understand these, it's necessary to understand a bit about how the workflow works.
7497

98+
The workflow opens connections either via a URL (`sftp://...` and `ssh://...` by default) or via a shell command (`ping` and `mosh` by default). URLs are passed off to the system, which opens them in the default application. Shell commands are handled by Alfred's [Terminal Command Action][termcmd], which effectively creates a new tab in your default terminal and pastes the command in there.
7599

76-
#### Using iTerm2
100+
101+
##### URLs #####
102+
103+
If you'd like `sftp://...` or `ssh://...` URLs to be passed to a specific application, specify its *name* for `SFTP_APP` or `SSH_APP` respectively, e.g. `Transmit` or `ForkLift` for SFTP, or `Terminal` for SSH.
104+
105+
106+
##### Commands #####
107+
108+
The handling of shell commands is configured in Alfred's own preferences (see [Using iTerm2](#using-iterm2) for more information).
109+
110+
There are two commands you can configure in the workflow, `MOSH_CMD` and `SSH_CMD`.
111+
112+
`MOSH_CMD` sets the command that is pasted in your terminal when the command is run. Normally, the default of `mosh` should be sufficient, but set to a full path if the command can't be found.
113+
114+
Set `MOSH_CMD` to empty to disable mosh.
115+
116+
`SSH_CMD` allows you to override the default behaviour of generating and opening an `ssh://...` URL. If `SSH_CMD` is non-empty, a shell command is generated and run in your terminal instead. `SSH_CMD` is the name or path of the `ssh` command.
117+
118+
Compared to the default `ssh://...` URL method, this has the advantage of running the command in your own shell, so your local configuration files should be loaded before the SSH connection is made. It has the downside of being slower and less well-tested than the default URL method.
119+
120+
121+
<a id="using-iterm2"></a>
122+
#### Using iTerm2 ####
77123

78124
If you'd prefer to use iTerm2 rather than Terminal.app, there are two steps:
79125

80-
1. To have `ping` and `mosh` commands open in iTerm2, install [@stuartcryan][stuart]'s [iTerm2 plugin for Alfred][iTerm2-plugin].
81-
2. To open `ssh:` connections in iTerm2, Set iTerm2 as the default handler for `ssh:` URLs in iTerm2's own preferences under `Profiles > PROFILE_NAME > General > URL Schemes`:
126+
1. To have shell commands open in iTerm2, install [@stuartcryan][stuart]'s [iTerm2 plugin for Alfred][iTerm2-plugin].
127+
2. To open `ssh://...` URLs in iTerm2, Set iTerm2 as the default handler for `ssh:` URLs in iTerm2's own preferences under `Profiles > PROFILE_NAME > General > URL Schemes`:
82128

83129
![iTerm2 > Preferences > PROFILE_NAME > General > URL Schemes][iTerm2-screenshot]
84130

85131

86-
Licencing & thanks
132+
<a id="licensing--thanks"></a>
133+
Licensing & thanks
87134
------------------
88135

89136
This workflow is released under the [MIT Licence][mit].
90137

91-
It uses the following libraries and resources:
138+
It uses the following libraries (all [MIT Licence][mit]):
139+
140+
- [ssh_config][ssh_config] to parse SSH config files.
141+
- [AwGo][awgo] for the workflowy stuff.
142+
143+
And icons from or based on the following fonts (all [SIL Licence][sil]):
92144

93-
- [ssh_config][ssh_config] ([MIT Licence][mit]) by [havoc-io][havoc-io] to parse SSH config files.
94-
- [awgo][awgo] ([MIT Licence][mit]) for the workflowy stuff.
95-
- The icon is based on [Octicons][octicons] ([SIL Licence][sil]) by [Github][gh].
145+
- [Octicons][octicons]
146+
- [Material Design Iconic Font][material]
147+
- [FontAwesome][fontawesome]
96148

97-
This workflow started as a port of [@isometry's][isometry] Python [SSH workflow][ssh-breathe] to Go as a testbed for [awgo][awgo]. It has since gained some additional features.
149+
This workflow started as a port of [@isometry's][isometry] Python [SSH workflow][ssh-breathe] to Go as a testbed for [AwGo][awgo]. It has since gained some additional features.
98150

99151
If you need Alfred 2 support, check out [@isometry's workflow][ssh-breathe].
100152

101153

154+
<a id="changelog"></a>
102155
Changelog
103156
---------
104157

158+
- v0.8.0 — 2018-03-17
159+
- Add option to use `ssh` command instead of URL.
160+
Enables loading of local shell configuration before opening connection. #8
161+
- Add in-workflow configuration of sources
162+
- Add links to docs, issue tracker and forum thread
105163
- v0.7.1 — 2016-12-12
106-
- Fix updater bug
107-
- Smarter SSH URLs for hosts from `~/.ssh/config`
108-
- Better removal of duplicates
164+
- Fix updater bug
165+
- Smarter SSH URLs for hosts from `~/.ssh/config`
166+
- Better removal of duplicates
109167
- v0.6.0 — 2016-11-09
110-
- Add in-workflow updates
168+
- Add in-workflow updates
111169
- v0.5.0 — 2016-10-31
112-
- Add support for SSH configuration files (`~/.ssh/config` and `/etc/ssh/ssh_config`)
113-
- Alternate action: open connection with `mosh`
170+
- Add support for SSH configuration files (`~/.ssh/config` and `/etc/ssh/ssh_config`)
171+
- Alternate action: open connection with `mosh`
114172
- v0.4.0 — 2016-05-27
115-
- Add ability to turn sources of suggestions off #1
173+
- Add ability to turn sources of suggestions off #1
116174
- v0.3.0 — 2016-05-26
117-
- Alternate action: Open SFTP connection
118-
- Alternate action: Ping host
119-
- Remember connections with usernames, so you don't have to type the username each time
175+
- Alternate action: Open SFTP connection
176+
- Alternate action: Ping host
177+
- Remember connections with usernames, so you don't have to type the username each time
120178
- v0.2.0 — 2016-05-23
121-
- First public release
179+
- First public release
122180

123181

124182
[alfredapp]: https://www.alfredapp.com/
125183
[alfterm]: https://www.alfredapp.com/help/features/terminal/
126-
[awgo]: https://godoc.org/gogs.deanishe.net/deanishe/awgo
184+
[awgo]: https://godoc.org/github.com/deanishe/awgo
185+
[confsheet]: https://www.alfredapp.com/help/workflows/advanced/variables/#environment
127186
[demo]: https://raw.githubusercontent.com/deanishe/alfred-ssh/master/demo.gif
128187
[gh-releases]: https://github.com/deanishe/alfred-ssh/releases/latest
129-
[gh]: https://github.com/
130-
[havoc-io]: https://github.com/havoc-io
131188
[isometry]: https://github.com/isometry
132189
[iTerm2-plugin]: https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/
133190
[iTerm2-screenshot]: https://raw.githubusercontent.com/deanishe/alfred-ssh/master/iTerm2.png "iTerm2 Preferences"
@@ -137,3 +194,6 @@ Changelog
137194
[ssh_config]: https://github.com/havoc-io/ssh_config
138195
[ssh-breathe]: https://github.com/isometry/alfredworkflows/tree/master/net.isometry.alfred.ssh
139196
[stuart]: https://github.com/stuartcryan/
197+
[termcmd]: https://www.alfredapp.com/help/workflows/actions/terminal-command/
198+
[material]: http://zavoloklom.github.io/material-design-iconic-font/
199+
[fontawesome]: https://fontawesome.com

alfred_env.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ export alfred_workflow_name=$( getvar "name" )
1515
export alfred_workflow_data="$HOME/Library/Application Support/Alfred 3/Workflow Data/$alfred_workflow_bundleid"
1616
export alfred_workflow_cache="$HOME/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/$alfred_workflow_bundleid"
1717
export alfred_debug='1'
18+
19+
export DISABLE_CONFIG=$( getvar "variables:DISABLE_CONFIG" )
20+
export DISABLE_ETC_CONFIG=$( getvar "variables:DISABLE_ETC_CONFIG" )
21+
export DISABLE_ETC_HOSTS=$( getvar "variables:DISABLE_ETC_HOSTS" )
22+
export DISABLE_HISTORY=$( getvar "variables:DISABLE_HISTORY" )
23+
export DISABLE_KNOWN_HOSTS=$( getvar "variables:DISABLE_KNOWN_HOSTS" )
24+
export EXIT_ON_SUCCESS=$( getvar "variables:EXIT_ON_SUCCESS" )
25+
export MOSH_CMD=$( getvar "variables:MOSH_CMD" )
26+
export SFTP_APP=$( getvar "variables:SFTP_APP" )
27+
export SSH_APP=$( getvar "variables:SSH_APP" )
28+
export SSH_CMD=$( getvar "variables:SSH_CMD" )
29+

0 commit comments

Comments
 (0)