Files
ts-scripts/single-scripts/ssh.ts

65 lines
1.5 KiB
TypeScript
Executable File

#!/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<string, SshProfile>;
}
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],
};
}