Skip to content

Commit

Permalink
Add source code
Browse files Browse the repository at this point in the history
  • Loading branch information
fbjorn committed Oct 5, 2020
1 parent 5e191f0 commit c5d9c14
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Alfred Workflow

on:
push:
tags:
- "*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build project
run: make pip
- name: Build Alfred Workflow
id: alfred_builder
uses: mperezi/build-alfred-workflow@v1
with:
workflow_dir: "."
exclude_patterns: ".git/* .github/* *.pyc *__pycache__/*"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Alfred Workflow
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.alfred_builder.outputs.workflow_file }}
asset_name: ${{ steps.alfred_builder.outputs.workflow_file }}
asset_content_type: application/zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
.idea
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/prettier/prettier
rev: master
hooks:
- id: prettier
12 changes: 12 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
printWidth: 80
trailingComma: "es5"
useTabs: false
tabWidth: 2
semi: false
singleQuote: false
endOfLine: "lf"
proseWrap: "always"
overrides:
- files: "*.yaml"
options:
proseWrap: "preserve"
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SRC := main.py info.plist lib icon.png
WF_DIR := ${HOME}/Documents/Alfred/Alfred.alfredpreferences/workflows/alfred-sshconfig
VERSION := $(shell grep -Eo 'string.*[0-9]+\.[0-9]+\.[0-9]+.*string' info.plist | cut -d">" -f2 | cut -d"<" -f1)

all: pip link

pip:
python2 -m pip install --upgrade pip
python2 -m pip install --target=./lib -r _requirements.txt

link:
mkdir -p "${WF_DIR}"
for f in ${SRC} ; do \
ln -sf "${PWD}/$$f" "${WF_DIR}/$$f"; \
done

clean:
for f in ${SRC} ; do \
unlink "${WF_DIR}/$$f"; \
done

release:
git tag ${VERSION}
git push origin ${VERSION}
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Installation

[Download](https://github.com/fbjorn/alfred-sshconfig/releases/) Alfred workflow
and open it

### Usage

Invoke Alfred and type `ssh`

Hosts from `~/.ssh/config` are parsed and prompted to the output. Choose
required one (fuzzy search supported) and press enter.

Alfred will open new tab in iTerm2 and will connect you to the host.

### Local development

```bash
make
```

It will create a `alfred-sshconfig` folder in your default Alfred installation
and add all required source files as symlinks.

Then just open Alfred on Workflows tab and you'll find it.

---

Made with [Alfred-Workflow](https://github.com/deanishe/alfred-workflow)

Bootstrapped from
[alfred-python-template](https://github.com/fbjorn/alfred-python-template)

Icons made by [Freepik](https://www.flaticon.com/authors/freepik) from
[Flaticon](https://www.flaticon.com/)
1 change: 1 addition & 0 deletions _requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Alfred-Workflow==1.40.0
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>com.fbjorn.sshconfig</string>
<key>category</key>
<string>Tools</string>
<key>connections</key>
<dict>
<key>F13B25B8-563C-44C1-880D-BA928913F3C2</key>
<array>
<dict>
<key>destinationuid</key>
<string>30F8B36C-F4D3-45CC-9530-FC356488B02D</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Denis Kirisov</string>
<key>description</key>
<string>Connect to server via SSH using iTerm2</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>SSH config</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>68</integer>
<key>script</key>
<string>on run argv
set theQuery to item 1 of argv
tell application "iTerm" tell current window create tab with default profile tell current tab tell current session write text "ssh " &amp; theQuery end tell end tell end tell end tell
activate application "iTerm"
end run</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>6</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>30F8B36C-F4D3-45CC-9530-FC356488B02D</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>ssh</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>PYTHONPATH=.:lib python2 main.py $1</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string>Connect to server via SSH</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>F13B25B8-563C-44C1-880D-BA928913F3C2</string>
<key>version</key>
<integer>3</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<key>uidata</key>
<dict>
<key>30F8B36C-F4D3-45CC-9530-FC356488B02D</key>
<dict>
<key>xpos</key>
<integer>425</integer>
<key>ypos</key>
<integer>180</integer>
</dict>
<key>F13B25B8-563C-44C1-880D-BA928913F3C2</key>
<dict>
<key>xpos</key>
<integer>175</integer>
<key>ypos</key>
<integer>180</integer>
</dict>
</dict>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.1.0</string>
<key>webaddress</key>
<string>https://github.com/fbjorn/alfred-sshconfig</string>
</dict>
</plist>
Expand Down
37 changes: 37 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# encoding: UTF-8
import os
import re
import sys

sys.path.append("lib") # noqa

from lib.workflow import Workflow3, Workflow


def get_hosts():
path = os.path.join(os.path.expanduser("~"), ".ssh", "config")
with open(path) as f:
conf = f.read()
hosts = re.findall(r"[\t ]*?Host[\t ]+?(.+)$", conf, re.MULTILINE)
return hosts


def main(wf):
# type: (Workflow) -> int

query = ""
if len(wf.args):
query = wf.args[0]

hosts = wf.cached_data("hosts", get_hosts, max_age=10)
hosts = wf.filter(query, hosts)
for host in hosts:
wf.add_item(title=host, valid=True, arg=host) # TODO: Add IP and user/keypair

wf.send_feedback()
return 0


if __name__ == "__main__":
workflow = Workflow3()
sys.exit(workflow.run(main))

0 comments on commit c5d9c14

Please sign in to comment.