Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CodeApp/Managers/TerminalInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,43 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
}
openSharedFilesApp(urlString: dir)
self.readLine()
case let x where x.hasPrefix("history"):
let args = x.components(separatedBy: " ")
if args.count == 1 {
// Display history with index in 2 tabbed columns (like ZSH)
// ZSH only displays the last 25 commands by default
// Format: index\t\tcommand
let script = """
var historyEntries = localEcho.history.entries;
if (historyEntries.length === 0) {
localEcho.println('');
} else {
// Display only the last 25 commands (ZSH behavior)
var startIndex = Math.max(0, historyEntries.length - 25);
for (var i = startIndex; i < historyEntries.length; i++) {
localEcho.println((i + 1) + '\\t\\t' + historyEntries[i]);
}
}
"""
executeScript(script)
self.readLine()
} else if args.count == 2 && args[1] == "-p" {
// Clear command history stored in local-echo.js (ZSH behavior)
// This accesses the HistoryController instance (localEcho.history)
// to reset both the entries array and cursor position
executeScript("localEcho.history.entries = []; localEcho.history.cursor = 0;")
self.readLine()
} else if args.count == 2 && (args[1] == "-h" || args[1] == "--help") {
// Display usage information
let usageMessage = "Usage: history [option]\\nOptions:\\n (no option) Display command history with index\\n -p Clear command history\\n -h, --help Display this help message"
executeScript("localEcho.println(`\(usageMessage)`);")
self.readLine()
} else {
// Invalid argument - show usage guidance
let errorMessage = "history: invalid option\\nTry 'history --help' for more information."
executeScript("localEcho.println(`\(errorMessage)`);")
self.readLine()
}
default:
let command = result["Input"] as! String
// guard command.count > 0 else {
Expand Down