-
Notifications
You must be signed in to change notification settings - Fork 116
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
Showing
21 changed files
with
389 additions
and
130 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,3 @@ | ||
module.exports = { | ||
extends: "extraterm" | ||
}; |
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 @@ | ||
Quick Open SSH session |
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,42 @@ | ||
{ | ||
"name": "ssh-quick-open", | ||
"description": "SSH Quick Open", | ||
"author": "Simon Edwards", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"exports": "./dist/SSHQuickOpenExtension.cjs", | ||
"scripts": { | ||
"build": "yarn run build-code && yarn run build-bundle && yarn run lint", | ||
"build-code": "tsc", | ||
"build-bundle": "esbuild build/SSHQuickOpenExtension.js --bundle --outfile=dist/SSHQuickOpenExtension.cjs --platform=node --format=cjs --external:@nodegui/nodegui \"--external:nodegui-plugin-*\"", | ||
"clean": "shx rm -rf build dist", | ||
"lint": "eslint \"src/**/*.ts\"", | ||
"lint-strict": "eslint --max-warnings 1 \"src/**/*.ts\"" | ||
}, | ||
"devDependencies": { | ||
"@extraterm/extraterm-extension-api": "0.15.0", | ||
"@types/fs-extra": "^5.0.2", | ||
"@types/lodash-es": "4.17.10", | ||
"@types/node": "^18.15.3", | ||
"esbuild": "^0.15.5", | ||
"eslint": "8.53.0", | ||
"eslint-config-extraterm": "1.0.0", | ||
"eslint-plugin-unicorn": "42.0.0", | ||
"extraterm-uuid": "1.0.0", | ||
"qt-construct": "0.1.0", | ||
"shx": "^0.3.2", | ||
"typescript": "5.2.2" | ||
}, | ||
"isInternal": false, | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "ssh-quick-open:open", | ||
"title": "SSH Quick Open", | ||
"category": "terminal", | ||
"icon": "fa-plug" | ||
} | ||
] | ||
} | ||
} |
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,71 @@ | ||
/* | ||
* Copyright 2024 Simon Edwards <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file. | ||
*/ | ||
import { ExtensionContext, Logger, SessionConfiguration } from '@extraterm/extraterm-extension-api'; | ||
import { createUuid } from "extraterm-uuid"; | ||
|
||
|
||
let log: Logger = null; | ||
let context: ExtensionContext = null; | ||
|
||
|
||
export function activate(_context: ExtensionContext): any { | ||
context = _context; | ||
log = context.logger; | ||
context.commands.registerCommand("ssh-quick-open:open", quickOpenCommand); | ||
} | ||
|
||
// Note: This is mostly duplicated in SSHSessionEditorExtension.ts. | ||
interface SSHSessionConfiguration extends SessionConfiguration { | ||
host?: string; | ||
port?: number; | ||
username?: string; | ||
authenticationMethod?: number; // AuthenticationMethod; | ||
} | ||
|
||
async function quickOpenCommand(): Promise<void> { | ||
const sshConnectionString = await context.activeTab.showTextInput({ | ||
message: "Enter a SSH connection string:", | ||
value: "", | ||
}); | ||
if (sshConnectionString == null) { | ||
return; | ||
} | ||
|
||
const sshSessionConfiguration = parseConnectionString(sshConnectionString); | ||
context.commands.executeCommand("extraterm:window.newTerminal", {sessionConfiguration: sshSessionConfiguration}); | ||
} | ||
|
||
function parseConnectionString(sshConnectionString: string): SSHSessionConfiguration { | ||
let username: string = null; | ||
|
||
const parts = sshConnectionString.split("@"); | ||
let hostnamePort = sshConnectionString; | ||
if (parts.length === 2) { | ||
username = parts[0]; | ||
hostnamePort = parts[1]; | ||
} | ||
|
||
const hostPortParts = hostnamePort.split(":"); | ||
let host: string = hostnamePort; | ||
let port = 22; | ||
if (hostPortParts.length === 2) { | ||
host = hostPortParts[0]; | ||
const parsedPort = parseInt(hostPortParts[1], 10); | ||
if (! isNaN(parsedPort)) { | ||
port = parsedPort; | ||
} | ||
} | ||
|
||
return { | ||
uuid: createUuid(), | ||
name: sshConnectionString, | ||
type: "ssh", | ||
authenticationMethod: 0, | ||
host, | ||
port, | ||
username, | ||
}; | ||
} |
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,10 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"rootDir": "src" | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
] | ||
} |
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
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
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
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
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
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
Oops, something went wrong.