From f2bbb49854d29ed395799bbdb6dae45374eaebad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 03:59:00 +0000 Subject: [PATCH 1/7] Initial plan From ea2d7398a316c349c17c25eaa03bd92a74874f67 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 04:02:33 +0000 Subject: [PATCH 2/7] Add support for 'history -c' command to clear terminal history Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> --- CodeApp/Managers/TerminalInstance.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index 015318310..43be7f855 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -319,6 +319,20 @@ 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 && args[1] == "-c" { + // Clear command history + executeScript("localEcho.history.entries = []; localEcho.history.cursor = 0;") + self.readLine() + } else { + // Display history - pass to ios_system for default behavior + executor?.dispatch(command: x, isInteractive: false) { _ in + DispatchQueue.main.async { + self.readLine() + } + } + } default: let command = result["Input"] as! String // guard command.count > 0 else { From 6d96d557885ab740d31ca9038a282e943b72bcb8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 04:05:11 +0000 Subject: [PATCH 3/7] Improve history command parsing to handle edge cases Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> --- CodeApp/Managers/TerminalInstance.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index 43be7f855..beaa41f71 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -320,8 +320,8 @@ 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 && args[1] == "-c" { + let args = x.split(separator: " ").map(String.init) + if args.count == 2 && args[1] == "-c" { // Clear command history executeScript("localEcho.history.entries = []; localEcho.history.cursor = 0;") self.readLine() From 453b07bebf9b83b53ac43f16eee2eca34fe456c5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 04:06:24 +0000 Subject: [PATCH 4/7] Add detailed comments explaining local-echo.js dependency Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> --- CodeApp/Managers/TerminalInstance.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index beaa41f71..44af22627 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -320,9 +320,11 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate { openSharedFilesApp(urlString: dir) self.readLine() case let x where x.hasPrefix("history"): - let args = x.split(separator: " ").map(String.init) + let args = x.components(separatedBy: " ") if args.count == 2 && args[1] == "-c" { - // Clear command history + // Clear command history stored in local-echo.js + // 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 { From 8ff488fb805e04c51628ecfad9c39217da9239d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 04:48:46 +0000 Subject: [PATCH 5/7] Use fallthrough for non-clear history commands Use fallthrough to default case instead of duplicating dispatch logic, as suggested in code review. Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> --- CodeApp/Managers/TerminalInstance.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index 44af22627..c2988225e 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -329,11 +329,7 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate { self.readLine() } else { // Display history - pass to ios_system for default behavior - executor?.dispatch(command: x, isInteractive: false) { _ in - DispatchQueue.main.async { - self.readLine() - } - } + fallthrough } default: let command = result["Input"] as! String From f445f5dc0f4b57ac04b236b31885b72cf758ba48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 15:59:54 +0000 Subject: [PATCH 6/7] 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> --- CodeApp/Managers/TerminalInstance.swift | 30 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index c2988225e..5a783e491 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -321,15 +321,37 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate { self.readLine() case let x where x.hasPrefix("history"): let args = x.components(separatedBy: " ") - if args.count == 2 && args[1] == "-c" { - // Clear command history stored in local-echo.js + if args.count == 1 { + // Display history with index in 2 tabbed columns (like ZSH) + // Format: index\t\tcommand + let script = """ + var historyEntries = localEcho.history.entries; + if (historyEntries.length === 0) { + localEcho.println(''); + } else { + for (var i = 0; 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 { - // Display history - pass to ios_system for default behavior - fallthrough + // 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 From 6cf74bdc60c56628ec77029727a4a2a63f53a690 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 16:16:23 +0000 Subject: [PATCH 7/7] Limit history display to last 25 commands (ZSH behavior) Modified history command to display only the last 25 commands when no arguments are provided, matching ZSH default behavior. Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com> --- CodeApp/Managers/TerminalInstance.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CodeApp/Managers/TerminalInstance.swift b/CodeApp/Managers/TerminalInstance.swift index 5a783e491..9cbec1d08 100644 --- a/CodeApp/Managers/TerminalInstance.swift +++ b/CodeApp/Managers/TerminalInstance.swift @@ -323,13 +323,16 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate { 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 { - for (var i = 0; i < historyEntries.length; i++) { + // 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]); } }