you can now find retrieve data using cat without changing the directory

This commit is contained in:
Brazly
2026-01-16 03:10:57 +00:00
parent 9c7d450154
commit 6ff1ab2670

View File

@@ -134,30 +134,53 @@ func ResolvePath(current: String, target: String) -> String:
return joined if joined.ends_with("/") else joined + "/" return joined if joined.ends_with("/") else joined + "/"
func GetDirAtPath(path: String): func GetDirAtPath(path: String):
if path == "~/": return fileSystem if path == "~/" or path == "": return fileSystem
var cleanPath = path.trim_prefix("~/").trim_suffix("/") var cleanPath = path.trim_prefix("~/").trim_suffix("/")
var folders = cleanPath.split("/") var folders = cleanPath.split("/")
var current = fileSystem var current = fileSystem
for folder in folders: for folder in folders:
if current is Dictionary and current.has(folder) and current[folder] is Dictionary: if folder == "": continue
if current is Dictionary and current.has(folder):
if current[folder] is Dictionary:
current = current[folder] current = current[folder]
else: else:
# We hit a file, not a directory
return null return null
return current if current is Dictionary else null else:
return null
return current
func RetrieveData(filename: String): func RetrieveData(inputPath: String):
var currentData = GetDirAtPath(directory) var targetFileName: String
if currentData == null: var targetDirData: Dictionary
CreateHistoryEntry("Error: Current directory invalid.")
if "/" in inputPath:
var pathParts = inputPath.rsplit("/", true, 1)
var dirPath = pathParts[0]
targetFileName = pathParts[1]
var resolvedDirPath = ResolvePath(directory, dirPath)
var result = GetDirAtPath(resolvedDirPath)
if result is Dictionary:
targetDirData = result
else:
CreateHistoryEntry("cat: " + dirPath + ": No such directory")
return return
if currentData.has(filename): else:
var content = currentData[filename] targetFileName = inputPath
targetDirData = GetDirAtPath(directory)
if targetDirData.has(targetFileName):
var content = targetDirData[targetFileName]
if content is Dictionary: if content is Dictionary:
CreateHistoryEntry("cat: " + filename + ": is a directory") CreateHistoryEntry("cat: " + targetFileName + ": Is a directory")
else: else:
CreateHistoryEntry(str(content)) CreateHistoryEntry(str(content))
else: else:
CreateHistoryEntry("cat: " + filename + ": no such file") CreateHistoryEntry("cat: " + targetFileName + ": No such file or directory")
func UpdateCaretPos(): func UpdateCaretPos():
var last_char_index = terminalLine.text.length() - 1 var last_char_index = terminalLine.text.length() - 1