diff --git a/index.html b/index.html index 0e69a0c..9625401 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@
-
root@browser:~$
+
root@browser:/$
diff --git a/scripts/index.js b/scripts/index.js index b9f312e..b0cbbdf 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -8,7 +8,10 @@ let commands = { "ls": {command: ls, description: "ls - List files in current directory"}, "cat": {command: cat, description: "cat - Show contents of a file"}, "touch": {command: touch, description: "touch - Create a new file"}, - "rm": {command: rm, description: "rm - Remove a file"} + "rm": {command: rm, description: "rm - Remove a file"}, + "arch": {command: arch, description: "arch - Show the architecture of the system"}, + "cd": {command: cd, description: "cd - Change directory"}, + "mkdir": {command: mkdir, description: "mkdir - Create a new directory"} } function exec(command, rw) { @@ -40,7 +43,7 @@ document.addEventListener('keydown', function (event) { terminalBody.innerHTML += '
'; rawInput = input; exec(input, rawInput); - terminalBody.innerHTML += "root@browser:~$ "; + terminalBody.innerHTML += "root@browser:"+ currentDir +"$ "; input = ''; terminalBody.scrollTop = terminalBody.scrollHeight - terminalBody.clientHeight; } diff --git a/scripts/terminalFunctions.js b/scripts/terminalFunctions.js index ccd170b..0853062 100644 --- a/scripts/terminalFunctions.js +++ b/scripts/terminalFunctions.js @@ -100,4 +100,41 @@ function rm(raw){ } storage.find(x => x.dirpath === currentDir).files.splice(fileIndex, 1) localStorage.setItem('dirs', JSON.stringify(storage)) +} + +function arch(){ + terminalWrite(navigator.userAgent) +} + +function cd(raw){ + let dir = raw.split(' ')[1] + if (!dir) { + terminalWrite('Usage: cd [directory]') + return; + } + if (dir === '..') { + currentDir = currentDir.split('/').slice(0, -1).join('/') + return; + } + let dirIndex = storage.findIndex(x => x.dirpath === currentDir + '/' + dir) + if (dirIndex === -1) { + terminalWrite('Directory not found') + return; + } + currentDir += '/' + dir +} + +function mkdir(raw){ + let dirname = raw.split(' ')[1] + if (!dirname) { + terminalWrite('Usage: mkdir [dirname]') + return; + } + let dir = { + dirname: dirname, + dirpath: currentDir + '/' + dirname, + files: [] + } + storage.push(dir) + localStorage.setItem('dirs', JSON.stringify(storage)) } \ No newline at end of file