class jssh { constructor(fs, working_dir, uid, input, h) { this.fs = fs; this.working_dir = working_dir; this.input = input; this.history = h; this.uid = uid; } set_wd(dir) { //let lwd = fs let wd = fs; let path = dir .split("/") .filter(function (e) { return e !== ""; }) .filter(function (e) { return e !== "."; }); for (let i in path) { if (path[i] == "..") { path.splice(i - 1, 2); } } for (let dir of path) { let found = false; //lwd = wd; if (dir != ".") { for (let i of wd) { if (i.name == dir && i.dir) { wd = i.content; found = true; break; } } if (!found) { return 1; } } } return wd; //return 1; } clean_path(path) { path = path .split("/") .filter(function (e) { return e !== ""; }) .filter(function (e) { return e.replace(" ", "") !== "."; }); for (let i = 0; i != path.length; i++) { if (path[i] == "..") { path.splice(i - 1, 2); return this.clean_path("/" + path.join("/")); } } if (path.includes("..")) path = []; return "/" + path.join("/"); } main() { for (let d of fs) { if (d.name == ".bashrc") { for (let line of d.content.split("\n").join("").split("")) { if (line.trim() != "") { document.getElementById(this.input).value = line.trim(); this.ex(); } } break; } } //setInterval(() => { // document.getElementById(this.input).focus(); //}, 10); } add_file(fs, path, dir) { //console.log(fs, path); if (path.length == 1) return fs.push({ name: path[0], perms: { r: true }, dir: dir, content: dir ? [] : "", }); for (let f in fs) { if (fs[f].name == path[0] && fs[f].dir) { fs = fs[f].content; path.splice(0, 1); return this.add_file(fs, path, dir); } } document.getElementById(this.history).innerHTML += "jssh: " + path.join("/") + ": directory not found"; } write_file(fs, path, content, append) { if (path.length == 1) { for (let f in fs) { if (fs[f].name == path[0] && !fs[f].dir) { fs[f].content = append ? fs[f].content + content : content; return fs; } } } /* return fs.push({ name: path[0], perms: { r: true }, dir: dir, content: dir ? [] : "", });*/ for (let f in fs) { if (fs[f].name == path[0] && fs[f].dir) { fs = fs[f].content; path.splice(0, 1); return this.write_file(fs, path, content, append); } } document.getElementById(this.history).innerHTML += "jssh: " + path.join("/") + ": file not found"; } rem_file(fs, path) { //console.log(fs, path); if (path.length == 1) { for (let f in fs) { console.log(f); if (fs[f].name == path[0]) { fs.splice(f, 1); break; } } return fs; } for (let f in fs) { if (fs[f].name == path[0] && fs[f].dir) { fs = fs[f].content; path.splice(0, 1); return this.rem_file(fs, path); } } document.getElementById(this.history).innerHTML += "jssh: " + path.join("/") + ": file or directory not found"; } ex() { let temp_working_dir = this.working_dir; //document.getElementById(this.history).innerHTML += // "λ " + document.getElementById(this.input).value + ""; let com = document.getElementById(this.input).value; let stripped = com.split(" "); let redir = false, redir_app = false; let history_write = ""; document.getElementById(this.history).innerHTML += "λ " + document.getElementById(this.input).value + ""; if (stripped.includes(">")) redir = true; else if (stripped.includes(">>")) redir_app = true; switch (stripped[0]) { case "touch": this.add_file( this.fs, this.clean_path( stripped[1][0] == "/" ? stripped[1] : this.working_dir + "/" + stripped[1] ) .split("/") .filter(function (e) { return e !== ""; }), false ); break; case "rm": this.rem_file( this.fs, this.clean_path( stripped[1][0] == "/" ? stripped[1] : this.working_dir + "/" + stripped[1] ) .split("/") .filter(function (e) { return e !== ""; }) ); break; case "mkdir": this.add_file( this.fs, this.clean_path( stripped[1][0] == "/" ? stripped[1] : this.working_dir + "/" + stripped[1] ) .split("/") .filter(function (e) { return e !== ""; }), true ); break; case "jssh": this.main(); break; case "neofetch": let add = ""; add += "
\ ,-. _,---._ __ / \\ \n \ / ) .-' `./ / \\ \n \ ( ( ,' `/ /| \n \ \\ `-\" '\\ / | \n \ `. , \\ / | \n \ /`. ,'-`----Y | \n \ ( ; | ' \n \ | ,-. ,-' | / \n \ | | ( | | / \n \ ) | \\ `.___________|/ \n \ `--' `--'"; //position this plz:) add += " | hello, i am amelia, they/themi am mostly a typescript and c++ dev, buti can work in most languages--i enjoy manga, and coding in free timecontact me at ameliasquires@disroot.org"; let colors = ["#cdb4db", "#ffc8dd", "#ffafcc", "#bde0fe", "#a2d2ff"]; for (let co of colors) { add += ""; } add += ""; colors = ["#a81d61", "#ff218e", "#fcd800", "#0194fc", "#007cd5"]; for (let co of colors) { add += ""; } add += " |