mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 21:07:04 +02:00
40b89baca1
* ns.ls filter can include leading slash in filename * scp from terminal accepts multiple filenames * terminal displays root / instead of ~ as base * cd with no args returns to root
15 lines
807 B
TypeScript
15 lines
807 B
TypeScript
import { Terminal } from "../../Terminal";
|
|
import { BaseServer } from "../../Server/BaseServer";
|
|
import { directoryExistsOnServer, resolveDirectory } from "../../Paths/Directory";
|
|
|
|
export function cd(args: (string | number | boolean)[], server: BaseServer): void {
|
|
if (args.length > 1) return Terminal.error("Incorrect number of arguments. Usage: cd [dir]");
|
|
// If no arg was provided, just use "/".
|
|
const userInput = String(args[0] ?? "/");
|
|
const targetDir = resolveDirectory(userInput, Terminal.currDir);
|
|
// Explicitly checking null due to root being ""
|
|
if (targetDir === null) return Terminal.error(`Could not resolve directory ${userInput}`);
|
|
if (!directoryExistsOnServer(targetDir, server)) return Terminal.error(`Directory ${targetDir} does not exist.`);
|
|
Terminal.setcwd(targetDir);
|
|
}
|