add set-hostname command
This commit is contained in:
parent
3bafeaa768
commit
a60f5485fc
|
@ -15,6 +15,7 @@ let cmds = {
|
||||||
'echo': require('./echo'),
|
'echo': require('./echo'),
|
||||||
'exit': require('./exit'),
|
'exit': require('./exit'),
|
||||||
'systemctl': require('./systemctl'),
|
'systemctl': require('./systemctl'),
|
||||||
|
'set-hostname': require('./set-hostname.js'),
|
||||||
|
|
||||||
|
|
||||||
'guide': require('./guide'),
|
'guide': require('./guide'),
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
const { Terminal } = require("xterm");
|
||||||
|
|
||||||
|
const original_data = Object.freeze(data);
|
||||||
|
global.orig = original_data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string[]} argv
|
||||||
|
* @param {Terminal} terminal
|
||||||
|
*/
|
||||||
|
module.exports = (argv, terminal, zsh) => {
|
||||||
|
if (argv.indexOf('--help') !== -1) {
|
||||||
|
terminal.writeln(`
|
||||||
|
Usage: ${argv[0]} [hostname] [-R] [--help]
|
||||||
|
-R Reset it to original IP (${original_data.ip})
|
||||||
|
--help Show this page`
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.indexOf('-R') !== -1) {
|
||||||
|
data.ip = original_data.ip;
|
||||||
|
zsh.update_prompt();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.ip = argv[1] || 'resume.js';
|
||||||
|
zsh.update_prompt();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -2,9 +2,18 @@
|
||||||
import { Terminal } from 'xterm';
|
import { Terminal } from 'xterm';
|
||||||
import { XTerm } from 'xterm-for-react';
|
import { XTerm } from 'xterm-for-react';
|
||||||
|
|
||||||
|
const memfs = require('memfs');
|
||||||
const fs = require('./fs');
|
const fs = require('./fs');
|
||||||
global.fs = fs;
|
global.fs = fs;
|
||||||
const cmds = require('./commands');
|
const cmds = require('./commands');
|
||||||
|
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 }
|
||||||
|
@ -16,10 +25,14 @@ let terminal;
|
||||||
*/
|
*/
|
||||||
let dom;
|
let dom;
|
||||||
|
|
||||||
const 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') || '';
|
||||||
|
|
||||||
|
function update_prompt() {
|
||||||
|
prompt = `\x1b[1;32muser@${data.ip} \x1b[36m~ $ \x1b[0m`;
|
||||||
|
}
|
||||||
|
|
||||||
function text_prompt() {
|
function text_prompt() {
|
||||||
return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
||||||
}
|
}
|
||||||
|
@ -44,13 +57,15 @@ function exec_file(f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const executable = fs.accessSync(f, fs.constants.X_OK);
|
// This fails for some reason (vvvv)
|
||||||
|
const executable = fs.accessSync(f, memfs.constants.X_OK);
|
||||||
|
// const executable = true;
|
||||||
if (!executable) {
|
if (!executable) {
|
||||||
terminal.writeln('zsh: permission denied: ' + f);
|
terminal.write('zsh: permission denied: ' + f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal.writeln('This is an online resume. It is not big enough to have a script runtime.\n');
|
terminal.writeln('This is just a simple online resume. It is not big enough to have a script runtime for god\'s sake.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +92,7 @@ async function exec_cmd() {
|
||||||
if (cmds[command] != undefined) {
|
if (cmds[command] != undefined) {
|
||||||
const startY = terminal.buffer.normal.cursorY
|
const startY = terminal.buffer.normal.cursorY
|
||||||
|
|
||||||
await cmds[command](c.split(' '), terminal);
|
await cmds[command](c.split(' '), terminal, zshapi);
|
||||||
|
|
||||||
await (new Promise(resolve => setTimeout(resolve, 10)));
|
|
||||||
|
|
||||||
if (terminal.buffer.active.cursorX != 0 && startY != terminal.buffer.active.cursorY) {
|
if (terminal.buffer.active.cursorX != 0 && startY != terminal.buffer.active.cursorY) {
|
||||||
terminal.write('\033[30;47m%\033[0m\n');
|
terminal.write('\033[30;47m%\033[0m\n');
|
||||||
|
|
Loading…
Reference in New Issue