Skip to content

Commit f445f5d

Browse files
Copilotbummoblizard
andcommitted
Implement ZSH-style history command behavior
- Change clear command from -c to -p (following ZSH) - Add history display with index in 2-column format when no args - Add usage guidance for --help and invalid options - Display "history: invalid option" message for incorrect arguments Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com>
1 parent 8ff488f commit f445f5d

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

CodeApp/Managers/TerminalInstance.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,37 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
321321
self.readLine()
322322
case let x where x.hasPrefix("history"):
323323
let args = x.components(separatedBy: " ")
324-
if args.count == 2 && args[1] == "-c" {
325-
// Clear command history stored in local-echo.js
324+
if args.count == 1 {
325+
// Display history with index in 2 tabbed columns (like ZSH)
326+
// Format: index\t\tcommand
327+
let script = """
328+
var historyEntries = localEcho.history.entries;
329+
if (historyEntries.length === 0) {
330+
localEcho.println('');
331+
} else {
332+
for (var i = 0; i < historyEntries.length; i++) {
333+
localEcho.println((i + 1) + '\\t\\t' + historyEntries[i]);
334+
}
335+
}
336+
"""
337+
executeScript(script)
338+
self.readLine()
339+
} else if args.count == 2 && args[1] == "-p" {
340+
// Clear command history stored in local-echo.js (ZSH behavior)
326341
// This accesses the HistoryController instance (localEcho.history)
327342
// to reset both the entries array and cursor position
328343
executeScript("localEcho.history.entries = []; localEcho.history.cursor = 0;")
329344
self.readLine()
345+
} else if args.count == 2 && (args[1] == "-h" || args[1] == "--help") {
346+
// Display usage information
347+
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"
348+
executeScript("localEcho.println(`\(usageMessage)`);")
349+
self.readLine()
330350
} else {
331-
// Display history - pass to ios_system for default behavior
332-
fallthrough
351+
// Invalid argument - show usage guidance
352+
let errorMessage = "history: invalid option\\nTry 'history --help' for more information."
353+
executeScript("localEcho.println(`\(errorMessage)`);")
354+
self.readLine()
333355
}
334356
default:
335357
let command = result["Input"] as! String

0 commit comments

Comments
 (0)