From 36f467fe2bec8b73163284392427ffa8c3be17cf Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 11 Jan 2026 11:00:19 +0800 Subject: [PATCH] ssh.ts working in process --- single-scripts/ssh.ts | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 single-scripts/ssh.ts diff --git a/single-scripts/ssh.ts b/single-scripts/ssh.ts new file mode 100755 index 0000000..9807a80 --- /dev/null +++ b/single-scripts/ssh.ts @@ -0,0 +1,64 @@ +#!/usr/bin/env runts -- --runtime-bun + +// reference: https://git.hatter.ink/rust-scripts/scriptbase/src/branch/main/ssh-rs/src/main.rs + +const { spawn } = require("node:child_process"); + +class SshTsArgs { + forward_agent?: boolean; + proxy?: boolean; + username_and_host?: string; +} + +interface SshConfig { + default_forward_agent?: boolean; + default_proxy?: boolean; + default_username?: string; + profiles: Map; +} + +interface SshProfile { + default_username?: string; + alias?: string[]; + host: string; + proxy?: boolean; + forward_agent?: boolean; + comment?: string; +} + +if (process.argv.length <= 2) { + console.log("help message"); + return; +} +const args = process.argv.slice(2); + +console.log(args); + +spawn("ssh", ["root@example.com"], { + shell: true, + stdio: ["inherit", "inherit", "inherit"], +}); + +interface UsernameAndHost { + username?: string; + host: string; +} + +function parseUsernameAndHost(usernameAndHost: string): UsernameAndHost { + if (!usernameAndHost) { + throw new Error('Empty username@host'); + } + const usernameAndHostParts = usernameAndHost.split('@'); + if (usernameAndHostParts.length ==1 ) { + return { + host: usernameAndHostParts[0], + }; + } + if (usernameAndHostParts.length > 2) { + throw new Error(`Base username@host: ${usernameAndHost}`); + } + return { + username: usernameAndHostParts[0], + host: usernameAndHostParts[1], + }; +}