diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fc80b11 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29cdfe1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib/ +.idea diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..643e7fa --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..350cd4f --- /dev/null +++ b/.prettierrc.yaml @@ -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" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b150c13 --- /dev/null +++ b/Makefile @@ -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} diff --git a/README.md b/README.md new file mode 100644 index 0000000..f42bd1f --- /dev/null +++ b/README.md @@ -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/) diff --git a/_requirements.txt b/_requirements.txt new file mode 100644 index 0000000..25462b4 --- /dev/null +++ b/_requirements.txt @@ -0,0 +1 @@ +Alfred-Workflow==1.40.0 diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..6a71d4c Binary files /dev/null and b/icon.png differ diff --git a/info.plist b/info.plist new file mode 100644 index 0000000..1c00baf --- /dev/null +++ b/info.plist @@ -0,0 +1,138 @@ + + + + + bundleid + com.fbjorn.sshconfig + category + Tools + connections + + F13B25B8-563C-44C1-880D-BA928913F3C2 + + + destinationuid + 30F8B36C-F4D3-45CC-9530-FC356488B02D + modifiers + 0 + modifiersubtext + + vitoclose + + + + + createdby + Denis Kirisov + description + Connect to server via SSH using iTerm2 + disabled + + name + SSH config + objects + + + config + + concurrently + + escaping + 68 + script + 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 " & theQuery end tell end tell end tell end tell + activate application "iTerm" +end run + scriptargtype + 1 + scriptfile + + type + 6 + + type + alfred.workflow.action.script + uid + 30F8B36C-F4D3-45CC-9530-FC356488B02D + version + 2 + + + config + + alfredfiltersresults + + alfredfiltersresultsmatchmode + 0 + argumenttreatemptyqueryasnil + + argumenttrimmode + 0 + argumenttype + 1 + escaping + 102 + keyword + ssh + queuedelaycustom + 3 + queuedelayimmediatelyinitially + + queuedelaymode + 0 + queuemode + 1 + runningsubtext + + script + PYTHONPATH=.:lib python2 main.py $1 + scriptargtype + 1 + scriptfile + + subtext + + title + Connect to server via SSH + type + 0 + withspace + + + type + alfred.workflow.input.scriptfilter + uid + F13B25B8-563C-44C1-880D-BA928913F3C2 + version + 3 + + + readme + + uidata + + 30F8B36C-F4D3-45CC-9530-FC356488B02D + + xpos + 425 + ypos + 180 + + F13B25B8-563C-44C1-880D-BA928913F3C2 + + xpos + 175 + ypos + 180 + + + variablesdontexport + + version + 0.1.0 + webaddress + https://github.com/fbjorn/alfred-sshconfig + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..08b881f --- /dev/null +++ b/main.py @@ -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))