Variables: The 0th frame is the global one, the next few ommits make it so

This commit is contained in:
Sekulum Forka 2021-05-17 17:02:51 +02:00
parent 2a732eb569
commit 8c48eb9057
1 changed files with 7 additions and 7 deletions

View File

@ -311,16 +311,16 @@ proc runBuiltin(builtin: string, args: openArray[string]): (string, int) =
of "cd": of "cd":
try: try:
if args.len == 0: if args.len == 0:
shellVariables[shellVariables.high]["LASTPWD"] = getCurrentDir() shellVariables[0]["LASTPWD"] = getCurrentDir()
setCurrentDir(getHomeDir()) setCurrentDir(getHomeDir())
return ("", 0) return ("", 0)
else: else:
if args[0] == "-": if args[0] == "-":
let LASTPWD = getCurrentDir() let LASTPWD = getCurrentDir()
setCurrentDir(shellVariables[shellVariables.high]["LASTPWD"]) setCurrentDir(shellVariables[0]["LASTPWD"])
shellVariables[shellVariables.high]["LASTPWD"] = LASTPWD shellVariables[0]["LASTPWD"] = LASTPWD
return ("", 0) return ("", 0)
shellVariables[shellVariables.high]["LASTPWD"] = getCurrentDir() shellVariables[0]["LASTPWD"] = getCurrentDir()
setCurrentDir(args[0]) setCurrentDir(args[0])
return ("", 0) return ("", 0)
except OsError as e: except OsError as e:
@ -375,12 +375,12 @@ when isMainModule:
setControlCHook(ctrlc) setControlCHook(ctrlc)
let stdinstrm = stdin.newFileStream let stdinstrm = stdin.newFileStream
# Set the default prompt # Set the default prompt
shellVariables[shellVariables.high]["PROMPT"] = "$PWD \\$" shellVariables[0]["PROMPT"] = "$PWD \\$"
stdout.write(shellVariables[shellVariables.high]["PROMPT"].newStringStream.substitute) stdout.write(shellVariables[0]["PROMPT"].newStringStream.substitute)
while not stdinstrm.atEnd(): while not stdinstrm.atEnd():
try: try:
discard stdinstrm.readCommand.execute discard stdinstrm.readCommand.execute
stdout.write(shellVariables[shellVariables.high]["PROMPT"].newStringStream.substitute) stdout.write(shellVariables[0]["PROMPT"].newStringStream.substitute)
except ShellError, ShellCommandError, ShellVariableError: except ShellError, ShellCommandError, ShellVariableError:
let e = getCurrentException() let e = getCurrentException()
stderr.write(e.msg, "\n") stderr.write(e.msg, "\n")