From b70d4ec3c7f878ab941b065d6d6f816c9edc1213 Mon Sep 17 00:00:00 2001 From: Aaron David Schneider Date: Sat, 25 Jun 2022 10:03:36 +0200 Subject: [PATCH 1/6] iterm ssh --- extensions/ssh-manager/package.json | 11 ++++ extensions/ssh-manager/src/show.tsx | 83 +++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/extensions/ssh-manager/package.json b/extensions/ssh-manager/package.json index ab821189d03..bbcbaed06ef 100644 --- a/extensions/ssh-manager/package.json +++ b/extensions/ssh-manager/package.json @@ -6,6 +6,17 @@ "icon": "command-icon.png", "author": "dimagrossman", "license": "MIT", + "preferences": [ + { + "name": "iterm", + "type": "checkbox", + "required": false, + "title": "Use iTerm instead of Terminal", + "description": "If iTerm is available, try to use iTerm instead of Terminal.", + "default": false, + "label": "Use iTerm" + } + ], "commands": [ { "name": "create", diff --git a/extensions/ssh-manager/src/show.tsx b/extensions/ssh-manager/src/show.tsx index 17a5e210aaf..85588f87a3e 100644 --- a/extensions/ssh-manager/src/show.tsx +++ b/extensions/ssh-manager/src/show.tsx @@ -1,9 +1,15 @@ -import { List, ActionPanel, showHUD } from "@raycast/api"; +import { List, ActionPanel, showHUD, getPreferenceValues } from "@raycast/api"; import { useEffect, useState } from "react"; import { runAppleScript } from "run-applescript"; import { ISSHConnection } from "./types"; import { getConnections, saveConnections } from "./storage.api"; +interface Preferences { + iterm: string; +} +const preferences = getPreferenceValues(); +export const use_iterm = preferences["iterm"]; + async function runTerminal(item: ISSHConnection) { let identity = ""; if (item.sshKey) { @@ -11,7 +17,7 @@ async function runTerminal(item: ISSHConnection) { } const command = `ssh ${identity} ${item.user}@${item.address}`; - const script = ` + const script_terminal = ` tell application "Terminal" do script "" activate @@ -25,8 +31,79 @@ async function runTerminal(item: ISSHConnection) { if result is not {} then perform action "AXRaise" of item 1 of result end tell `; + const script_iterm = ` + on new_window() + tell application "iTerm" to create window with default profile + end new_window + + on new_tab() + tell application "iTerm" to tell the first window to create tab with default profile + end new_tab + + on call_forward() + tell application "iTerm" to activate + end call_forward + + on is_running() + application "iTerm" is running + end is_running + + on is_processing() + tell application "iTerm" to tell the first window to tell current session to get is processing + end is_processing + + on has_windows() + if not is_running() then return false + if windows of application "iTerm" is {} then return false + true + end has_windows + + on send_text(custom_text) + tell application "iTerm" to tell the first window to tell current session to write text custom_text + end send_text + + -- Main + if has_windows() then + -- Open the command in the current session unless it has a running command, e.g., ssh or top + if is_processing() then + if open_in_new_window then + new_window() + else + new_tab() + end if + end if + else + -- If iTerm is not running and we tell it to create a new window, we get two + -- One from opening the application, and the other from the command + if is_running() then + new_window() + else + call_forward() + end if + end if + + -- Make sure a window exists before we continue, or the write may fail + repeat until has_windows() + delay 0.01 + end repeat + + send_text("${command}") + call_forward() + `; + + if (use_iterm) { + try { + await runAppleScript(script_iterm); + } + catch (error) { + await runAppleScript(script_terminal); + console.log(error) + } + } + else { + await runAppleScript(script_terminal); + } - await runAppleScript(script); await showHUD("Success ✅"); } From c0ffd2b5e52ffeabc3d5cbdddf8408e8d42db357 Mon Sep 17 00:00:00 2001 From: Aaron David Schneider Date: Sat, 25 Jun 2022 16:37:30 +0200 Subject: [PATCH 2/6] fix lint --- extensions/ssh-manager/package.json | 3 ++- extensions/ssh-manager/src/show.tsx | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/extensions/ssh-manager/package.json b/extensions/ssh-manager/package.json index bbcbaed06ef..1041674177b 100644 --- a/extensions/ssh-manager/package.json +++ b/extensions/ssh-manager/package.json @@ -52,6 +52,7 @@ "scripts": { "build": "ray build -e dist", "dev": "ray develop", - "lint": "ray lint" + "lint": "ray lint", + "fix-lint": "ray lint --fix" } } diff --git a/extensions/ssh-manager/src/show.tsx b/extensions/ssh-manager/src/show.tsx index 85588f87a3e..46487ba5a83 100644 --- a/extensions/ssh-manager/src/show.tsx +++ b/extensions/ssh-manager/src/show.tsx @@ -32,6 +32,9 @@ async function runTerminal(item: ISSHConnection) { end tell `; const script_iterm = ` + -- Set this property to true to open in a new window instead of a new tab + property open_in_new_window : false + on new_window() tell application "iTerm" to create window with default profile end new_window @@ -94,13 +97,11 @@ async function runTerminal(item: ISSHConnection) { if (use_iterm) { try { await runAppleScript(script_iterm); - } - catch (error) { + } catch (error) { await runAppleScript(script_terminal); - console.log(error) + console.log(error); } - } - else { + } else { await runAppleScript(script_terminal); } From 33f3324c4f23dd606ee8ef4d78df13db971af5a7 Mon Sep 17 00:00:00 2001 From: Aaron David Schneider Date: Sat, 25 Jun 2022 16:42:58 +0200 Subject: [PATCH 3/6] var renaming --- extensions/ssh-manager/src/show.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extensions/ssh-manager/src/show.tsx b/extensions/ssh-manager/src/show.tsx index 46487ba5a83..2e99c681a59 100644 --- a/extensions/ssh-manager/src/show.tsx +++ b/extensions/ssh-manager/src/show.tsx @@ -8,7 +8,7 @@ interface Preferences { iterm: string; } const preferences = getPreferenceValues(); -export const use_iterm = preferences["iterm"]; +export const useIterm = preferences["iterm"]; async function runTerminal(item: ISSHConnection) { let identity = ""; @@ -17,7 +17,7 @@ async function runTerminal(item: ISSHConnection) { } const command = `ssh ${identity} ${item.user}@${item.address}`; - const script_terminal = ` + const scriptTerminal = ` tell application "Terminal" do script "" activate @@ -31,7 +31,7 @@ async function runTerminal(item: ISSHConnection) { if result is not {} then perform action "AXRaise" of item 1 of result end tell `; - const script_iterm = ` + const scriptIterm = ` -- Set this property to true to open in a new window instead of a new tab property open_in_new_window : false @@ -94,15 +94,15 @@ async function runTerminal(item: ISSHConnection) { call_forward() `; - if (use_iterm) { + if (useIterm) { try { - await runAppleScript(script_iterm); + await runAppleScript(scriptIterm); } catch (error) { - await runAppleScript(script_terminal); + await runAppleScript(scriptTerminal); console.log(error); } } else { - await runAppleScript(script_terminal); + await runAppleScript(scriptTerminal); } await showHUD("Success ✅"); From 207228ea24e48c7e61e37cd002c4db01365ebcf7 Mon Sep 17 00:00:00 2001 From: Aaron David Schneider Date: Tue, 28 Jun 2022 11:41:19 +0200 Subject: [PATCH 4/6] - add CHANGELOG.md - dropdown instead --- extensions/ssh-manager/CHANGELOG.md | 7 +++++++ extensions/ssh-manager/package.json | 24 +++++++++++++++++------- extensions/ssh-manager/src/show.tsx | 6 +++--- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 extensions/ssh-manager/CHANGELOG.md diff --git a/extensions/ssh-manager/CHANGELOG.md b/extensions/ssh-manager/CHANGELOG.md new file mode 100644 index 00000000000..b6c1238c14c --- /dev/null +++ b/extensions/ssh-manager/CHANGELOG.md @@ -0,0 +1,7 @@ +# ssh-manager Changelog + +## [Initial Version] - 2022-04-05 + +## [Add iTerm Support] - 2022-06-28 +This version adds the option to add ssh connections in iTerm. +Checkout the preferences and select iTerm in the dropdown to get going. \ No newline at end of file diff --git a/extensions/ssh-manager/package.json b/extensions/ssh-manager/package.json index 1041674177b..f5200d8b500 100644 --- a/extensions/ssh-manager/package.json +++ b/extensions/ssh-manager/package.json @@ -8,14 +8,24 @@ "license": "MIT", "preferences": [ { - "name": "iterm", - "type": "checkbox", + "name": "terminal", + "type": "dropdown", "required": false, - "title": "Use iTerm instead of Terminal", - "description": "If iTerm is available, try to use iTerm instead of Terminal.", - "default": false, - "label": "Use iTerm" - } + "title": "Decide which Terminal Application you want to use", + "description": "If iTerm is available, you can use iTerm instead of Terminal.", + "label": "Use iTerm", + "data": [{ + "title": "Terminal", + "value": "Terminal" + }, + { + "title": "iTerm", + "value": "iTerm" + } + ], + "default": "Terminal" + } + ], "commands": [ { diff --git a/extensions/ssh-manager/src/show.tsx b/extensions/ssh-manager/src/show.tsx index 2e99c681a59..63615f3fd86 100644 --- a/extensions/ssh-manager/src/show.tsx +++ b/extensions/ssh-manager/src/show.tsx @@ -5,10 +5,10 @@ import { ISSHConnection } from "./types"; import { getConnections, saveConnections } from "./storage.api"; interface Preferences { - iterm: string; + terminal: string; } const preferences = getPreferenceValues(); -export const useIterm = preferences["iterm"]; +export const terminal = preferences["terminal"]; async function runTerminal(item: ISSHConnection) { let identity = ""; @@ -94,7 +94,7 @@ async function runTerminal(item: ISSHConnection) { call_forward() `; - if (useIterm) { + if (terminal == "iTerm") { try { await runAppleScript(scriptIterm); } catch (error) { From 2571c4fdaaf6d9862ce1fccac1a966ecf38ff396 Mon Sep 17 00:00:00 2001 From: Aaron David Schneider Date: Tue, 28 Jun 2022 11:49:43 +0200 Subject: [PATCH 5/6] drop forgotten label --- extensions/ssh-manager/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/ssh-manager/package.json b/extensions/ssh-manager/package.json index f5200d8b500..d636a6226e8 100644 --- a/extensions/ssh-manager/package.json +++ b/extensions/ssh-manager/package.json @@ -13,7 +13,6 @@ "required": false, "title": "Decide which Terminal Application you want to use", "description": "If iTerm is available, you can use iTerm instead of Terminal.", - "label": "Use iTerm", "data": [{ "title": "Terminal", "value": "Terminal" From ca94c529a864a6f7ab94f53f488bfa31b599b4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Nielsen=20Tik=C3=A6r?= Date: Tue, 28 Jun 2022 15:45:24 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md --- extensions/ssh-manager/CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/ssh-manager/CHANGELOG.md b/extensions/ssh-manager/CHANGELOG.md index b6c1238c14c..c436708cfd2 100644 --- a/extensions/ssh-manager/CHANGELOG.md +++ b/extensions/ssh-manager/CHANGELOG.md @@ -1,7 +1,7 @@ # ssh-manager Changelog -## [Initial Version] - 2022-04-05 - ## [Add iTerm Support] - 2022-06-28 This version adds the option to add ssh connections in iTerm. -Checkout the preferences and select iTerm in the dropdown to get going. \ No newline at end of file +Checkout the preferences and select iTerm in the dropdown to get going. + +## [Initial Version] - 2022-04-05