-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0e62da9
Showing
8 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*~ | ||
tty.alfred3workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Robin Breathe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
zip -j9 --filesync tty.alfred3workflow *.{plist,png,js} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# ^TTY workflow for Alfred | ||
|
||
A JXA-based workflow for [Alfred](http://www.alfredapp.com/) Powerpack users to quickly switch between or close iTerm windows, tabs and panes based on title and tty. | ||
|
||
## Releases | ||
- [Latest for Alfred 3.x](https://github.com/isometry/alfred-tty/releases/latest) | ||
|
||
## Prerequisites | ||
|
||
- [Alfred](http://www.alfredapp.com/) (version 3.x) | ||
- The [Alfred Powerpack](http://www.alfredapp.com/powerpack/) | ||
- macOS Sierra or newer (strictly, Mac OS X 10.10+, but untested on <10.12) | ||
|
||
## Usage | ||
|
||
Type `tty` in Alfred followed by some characters from the title of an open window, tab or pane; press `Enter` to activate the selected window/tab/pane, or Alt-Enter` to close it. For example, enter `tty as3` to switch to a tab with the title `user@azure-server-03`. | ||
|
||
In order to make working with more than one window/tab/pane with the same title easier, the tty is displayed beneath the result, and can be provided as a second argument to the trigger. For example, enter `tty lo 3` to select the the session with title `localhost` running on `/dev/ttys003`. | ||
|
||
To select by tty alone, use two spaces between the trigger and the tty number. For example, `tty 4` will select `/dev/ttys004`. | ||
|
||
Optionally associate a hotkey trigger to further accelerate operation, e.g. Ctrl+Alt+T. | ||
|
||
Combine with an ssh protocol handler [iTerm2](https://www.iterm2.com/) profile (e.g. "Name"=`$$USER$$@$$HOST$$`, "Command"=`$$` and "Schemes handled"=`ssh`) and an ssh workflow (e.g. [alfred-ssh](https://github.com/isometry/alfred-ssh)) to make opening and jumping between remote sessions across many windows, tabs and panes easy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env osascript -l JavaScript | ||
|
||
function run(args) | ||
{ | ||
args = args.join(" ").split(" ").map(function(e,i){return i==0?String(e):Number(e)}); | ||
var app = Application("com.googlecode.iterm2"); | ||
var action = args[0]; | ||
var win = app.windows[args[1]]; | ||
var tab = win.tabs[args[2]]; | ||
var ses = tab.sessions[args[3]]; | ||
switch (action) { | ||
case "select": | ||
// tab => session => window => app | ||
tab.select(); | ||
ses.select(); | ||
win.select(); | ||
app.activate(); | ||
break; | ||
case "close": | ||
var old = win.currentTab(); | ||
tab.select(); | ||
ses.close(); | ||
old.select(); | ||
break; | ||
default: | ||
console.info(JSON.stringify({args:args, title:ses.name()})); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env osascript -l JavaScript | ||
|
||
function sessionToObj(winId, tabId) { | ||
return function(session, sesId) { | ||
return { | ||
id: [winId, tabId, sesId].join(" "), | ||
title: session.name(), | ||
tty: session.tty(), | ||
output: session.isProcessing(), | ||
profile: session.profileName() | ||
} | ||
} | ||
} | ||
|
||
function objToItem(obj) { | ||
var description = obj.tty + (obj.output?" *":""); | ||
return { | ||
title: obj.title, | ||
subtitle: ["Select", description].join(" "), | ||
arg: ["select", obj.id].join(" "), | ||
uid: [obj.title, obj.profile].join("/"), | ||
icon: { path: "icon.png" }, | ||
mods: { | ||
alt: { | ||
arg: ["close", obj.id].join(" "), | ||
subtitle: ["Close", description].join(" ") | ||
} | ||
} | ||
} | ||
} | ||
|
||
function allSessionObjs(app) { | ||
var windows = app.windows; | ||
var results = new Array(); | ||
for (var i = 0; i < windows.length; ++i) { | ||
var tabs = windows[i].tabs; | ||
for (var j = 0; j < tabs.length; ++j) { | ||
results.push(...tabs[j].sessions().map(sessionToObj(i, j))); | ||
} | ||
} | ||
return results; | ||
} | ||
|
||
function titleFilter(pattern) { | ||
var re = new RegExp(pattern.replace(/./g, "$&.*?")); | ||
return function(obj) { | ||
return re.exec(obj.title); | ||
} | ||
} | ||
|
||
function ttyFilter(ttyNum) { | ||
if (ttyNum.length == 0) { | ||
return function() {return true;}; | ||
} else { | ||
var re = new RegExp(ttyNum.padStart(3, "0") + "$"); | ||
return function(obj) { | ||
return re.exec(obj.tty); | ||
}; | ||
} | ||
} | ||
|
||
function run(args) { | ||
args = args.join(" ").split(" "); | ||
var titlePattern = String(args[0] || ""); | ||
var ttyPattern = String(args[1] || ""); | ||
var sessionObjs = new Array(); | ||
var app = Application("com.googlecode.iterm2"); | ||
if (app.running()) { | ||
sessionObjs = allSessionObjs(app).filter(titleFilter(titlePattern)).filter(ttyFilter(ttyPattern)); | ||
} | ||
return JSON.stringify({items: sessionObjs.map(objToItem)}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<?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>net.isometry.alfred.tty</string> | ||
<key>category</key> | ||
<string>Tools</string> | ||
<key>connections</key> | ||
<dict> | ||
<key>45E888C5-D745-4FEC-B0CC-80C4A33371F8</key> | ||
<array> | ||
<dict> | ||
<key>destinationuid</key> | ||
<string>C9298943-AE22-4585-8C3B-4A3E72EEAAA4</string> | ||
<key>modifiers</key> | ||
<integer>0</integer> | ||
<key>modifiersubtext</key> | ||
<string></string> | ||
<key>vitoclose</key> | ||
<false/> | ||
</dict> | ||
</array> | ||
<key>C9298943-AE22-4585-8C3B-4A3E72EEAAA4</key> | ||
<array> | ||
<dict> | ||
<key>destinationuid</key> | ||
<string>83C7D354-7702-4395-AA13-7F6F3E1EC22F</string> | ||
<key>modifiers</key> | ||
<integer>0</integer> | ||
<key>modifiersubtext</key> | ||
<string></string> | ||
<key>vitoclose</key> | ||
<false/> | ||
</dict> | ||
</array> | ||
</dict> | ||
<key>createdby</key> | ||
<string>Robin Breathe</string> | ||
<key>description</key> | ||
<string>Select or close windows, tabs and panes in iTerm2</string> | ||
<key>disabled</key> | ||
<false/> | ||
<key>name</key> | ||
<string>^tty</string> | ||
<key>objects</key> | ||
<array> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>alfredfiltersresults</key> | ||
<false/> | ||
<key>alfredfiltersresultsmatchmode</key> | ||
<integer>0</integer> | ||
<key>argumenttrimmode</key> | ||
<integer>0</integer> | ||
<key>argumenttype</key> | ||
<integer>1</integer> | ||
<key>escaping</key> | ||
<integer>0</integer> | ||
<key>keyword</key> | ||
<string>tty</string> | ||
<key>queuedelaycustom</key> | ||
<integer>3</integer> | ||
<key>queuedelayimmediatelyinitially</key> | ||
<false/> | ||
<key>queuedelaymode</key> | ||
<integer>1</integer> | ||
<key>queuemode</key> | ||
<integer>2</integer> | ||
<key>runningsubtext</key> | ||
<string>Please wait…</string> | ||
<key>script</key> | ||
<string>./filter-tty.js "$@"</string> | ||
<key>scriptargtype</key> | ||
<integer>1</integer> | ||
<key>scriptfile</key> | ||
<string>filter-tty.js</string> | ||
<key>subtext</key> | ||
<string></string> | ||
<key>title</key> | ||
<string>Select or close an iTerm window, tab or pane</string> | ||
<key>type</key> | ||
<integer>8</integer> | ||
<key>withspace</key> | ||
<true/> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.input.scriptfilter</string> | ||
<key>uid</key> | ||
<string>C9298943-AE22-4585-8C3B-4A3E72EEAAA4</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>action</key> | ||
<integer>0</integer> | ||
<key>argument</key> | ||
<integer>0</integer> | ||
<key>focusedappvariable</key> | ||
<false/> | ||
<key>focusedappvariablename</key> | ||
<string></string> | ||
<key>hotkey</key> | ||
<integer>40</integer> | ||
<key>hotmod</key> | ||
<integer>786432</integer> | ||
<key>hotstring</key> | ||
<string>T</string> | ||
<key>leftcursor</key> | ||
<false/> | ||
<key>modsmode</key> | ||
<integer>0</integer> | ||
<key>relatedAppsMode</key> | ||
<integer>0</integer> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.trigger.hotkey</string> | ||
<key>uid</key> | ||
<string>45E888C5-D745-4FEC-B0CC-80C4A33371F8</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>concurrently</key> | ||
<false/> | ||
<key>escaping</key> | ||
<integer>0</integer> | ||
<key>script</key> | ||
<string></string> | ||
<key>scriptargtype</key> | ||
<integer>1</integer> | ||
<key>scriptfile</key> | ||
<string>action-tty.js</string> | ||
<key>type</key> | ||
<integer>8</integer> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.action.script</string> | ||
<key>uid</key> | ||
<string>83C7D354-7702-4395-AA13-7F6F3E1EC22F</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
</array> | ||
<key>readme</key> | ||
<string>Type `tty` in Alfred followed by some characters from the title of an open tab or pane; press `Enter` to activate the selected pane, or Alt-Enter` to close it. For example, enter `tty as3` to switch to a tab with the title `user@azure-server-03`. | ||
In order to make working with more than one window/tab/pane with the same title easier, the TTY is displayed beneath the result, and can be provided as a second argument to the trigger, e.g. `tty lo 3` to select the the session with title `localhost` running on `/dev/ttys003`. | ||
Optionally associate a hotkey trigger to further accelerate operation, e.g. Ctrl+Alt+T. | ||
Combine with an ssh protocol handler [iTerm2](https://www.iterm2.com/) profile (e.g. "Name"=`$$USER$$@$$HOST$$`, "Command"=`$$` and "Schemes handled"=`ssh`) and an ssh workflow (e.g. [alfred-ssh](https://github.com/isometry/alfred-ssh)) to make opening and jumping between remote sessions across many windows, tabs and panes easy.</string> | ||
<key>uidata</key> | ||
<dict> | ||
<key>45E888C5-D745-4FEC-B0CC-80C4A33371F8</key> | ||
<dict> | ||
<key>xpos</key> | ||
<integer>70</integer> | ||
<key>ypos</key> | ||
<integer>70</integer> | ||
</dict> | ||
<key>83C7D354-7702-4395-AA13-7F6F3E1EC22F</key> | ||
<dict> | ||
<key>note</key> | ||
<string>action-tty.js</string> | ||
<key>xpos</key> | ||
<integer>430</integer> | ||
<key>ypos</key> | ||
<integer>70</integer> | ||
</dict> | ||
<key>C9298943-AE22-4585-8C3B-4A3E72EEAAA4</key> | ||
<dict> | ||
<key>note</key> | ||
<string>filter-tty.js</string> | ||
<key>xpos</key> | ||
<integer>250</integer> | ||
<key>ypos</key> | ||
<integer>70</integer> | ||
</dict> | ||
</dict> | ||
<key>version</key> | ||
<string>1.0</string> | ||
<key>webaddress</key> | ||
<string>https://github.com/isometry/alfred-tty</string> | ||
</dict> | ||
</plist> |