fix set-hostname

This commit is contained in:
b1ek 2023-05-05 01:25:55 +10:00
parent 04133aa313
commit 2f3ccae2f4
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 23 additions and 15 deletions

View File

@ -1,7 +1,6 @@
const { Terminal } = require("xterm"); const { Terminal } = require("xterm");
const original_data = Object.freeze(data); const orig_ip = data.ip;
global.orig = original_data;
/** /**
* *
@ -9,22 +8,21 @@ global.orig = original_data;
* @param {Terminal} terminal * @param {Terminal} terminal
*/ */
module.exports = (argv, terminal, zsh) => { module.exports = (argv, terminal, zsh) => {
if (argv.indexOf('--help') !== -1) { if (argv.indexOf('--help') !== -1 | (!argv[1])) {
terminal.writeln(` terminal.writeln(`Usage: ${argv[0]} [hostname] [-R] [--help]
Usage: ${argv[0]} [hostname] [-R] [--help] -R Reset it to original IP (${orig_ip})
-R Reset it to original IP (${original_data.ip})
--help Show this page` --help Show this page`
); );
return 0; return 0;
} }
if (argv.indexOf('-R') !== -1) { if (argv.indexOf('-R') !== -1) {
data.ip = original_data.ip; data.ip = orig_ip;
zsh.update_prompt(); zsh.update_prompt();
return 0; return 0;
} }
data.ip = argv[1] || 'resume.js'; data.ip = argv[1];
zsh.update_prompt(); zsh.update_prompt();
return 0; return 0;
} }

View File

@ -8,13 +8,6 @@ global.fs = fs;
const cmds = require('./commands'); const cmds = require('./commands');
const sleep = require('../lib/sleep'); const sleep = require('../lib/sleep');
// ZSH api to be used in commands (see references)
const zshapi = {
update_prompt,
text_prompt,
pr_char
};
/** /**
* @type { Terminal } * @type { Terminal }
*/ */
@ -25,6 +18,15 @@ let terminal;
*/ */
let dom; let dom;
// ZSH api to be used in commands (see references)
const zshapi = {
update_prompt,
text_prompt,
pr_char,
terminal,
dom
};
let prompt = `\x1b[1;32muser@${data.ip} \x1b[36m~ $ \x1b[0m`; let prompt = `\x1b[1;32muser@${data.ip} \x1b[36m~ $ \x1b[0m`;
let cmd = ''; let cmd = '';
let lastcmd = window.sessionStorage.getItem('last_cmd') || ''; let lastcmd = window.sessionStorage.getItem('last_cmd') || '';
@ -40,6 +42,14 @@ function text_prompt() {
/** /**
* *
* @param { string } char * @param { string } char
// ZSH api to be used in commands (see references)
const zshapi = {
update_prompt,
text_prompt,
pr_char,
terminal,
dom
};
* @param { KeyboardEvent } dom * @param { KeyboardEvent } dom
*/ */
function pr_char(char, dom) { function pr_char(char, dom) {