feat: ssh.ts
This commit is contained in:
@@ -7,9 +7,16 @@ const { parseArgs } = require("node:util");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
|
||||
// reference: https://bun.com/docs/runtime/color
|
||||
const GREEN = Bun.color("green", "ansi");
|
||||
const BLUE = Bun.color("lightblue", "ansi");
|
||||
const YELLOW = Bun.color("yellow", "ansi");
|
||||
const RESET = "\x1B[0m";
|
||||
|
||||
class SshTsArgs {
|
||||
forwardAgent?: boolean;
|
||||
proxy?: boolean;
|
||||
help?: boolean;
|
||||
host?: string;
|
||||
}
|
||||
|
||||
@@ -48,11 +55,6 @@ function printSshConfig(sshConfig: SshConfig) {
|
||||
maxProfileHostLength = sshProfile.host.length;
|
||||
}
|
||||
}
|
||||
// reference: https://bun.com/docs/runtime/color
|
||||
const GREEN = Bun.color("green", "ansi");
|
||||
const BLUE = Bun.color("lightblue", "ansi");
|
||||
const YELLOW = Bun.color("yellow", "ansi");
|
||||
const RESET = "\x1B[0m";
|
||||
console.log(
|
||||
`${GREEN}[OK ]${RESET} Total ${allProfiles.length} server(s):`,
|
||||
);
|
||||
@@ -140,15 +142,36 @@ async function main() {
|
||||
type: "boolean",
|
||||
short: "p",
|
||||
},
|
||||
"help": {
|
||||
type: "boolean",
|
||||
short: "h",
|
||||
},
|
||||
"host": {
|
||||
type: "string",
|
||||
short: "h",
|
||||
short: "H",
|
||||
},
|
||||
};
|
||||
|
||||
const { values, tokens } = parseArgs({ args, options, tokens: true });
|
||||
const { values, positionals } = parseArgs({
|
||||
args,
|
||||
options,
|
||||
allowPositionals: true,
|
||||
tokens: true,
|
||||
});
|
||||
const sshTsArgs = values as SshTsArgs;
|
||||
if (sshTsArgs.help) {
|
||||
console.log("ssh.ts [-h|--help]");
|
||||
console.log(
|
||||
"ssh.ts [-f|--forward-agent] [-p|--proxy] [-H|--host] [username@]host",
|
||||
);
|
||||
console.log("ssh.ts [-f|--forward-agent] [-p|--proxy] [username@]host");
|
||||
return;
|
||||
}
|
||||
|
||||
sshTsArgs.forwardAgent = values["forward-agent"];
|
||||
if (!sshTsArgs.host && positionals && positionals.length > 0) {
|
||||
sshTsArgs.host = positionals[0];
|
||||
}
|
||||
if (!sshTsArgs.host) {
|
||||
console.error("[ERROR] --host required");
|
||||
return;
|
||||
@@ -182,7 +205,7 @@ async function main() {
|
||||
`${sshUsername}@${sshProfile.host}`,
|
||||
);
|
||||
|
||||
console.log(`Command: ${sshCommand} ${sshArgs.join(" ")}`);
|
||||
console.log(`${GREEN}[OK ]${RESET} ${sshCommand} ${sshArgs.join(" ")}`);
|
||||
spawn(sshCommand, sshArgs, {
|
||||
shell: true,
|
||||
stdio: ["inherit", "inherit", "inherit"],
|
||||
|
||||
Reference in New Issue
Block a user