| 18 | |
| 19 | // Shell history parsing functions |
| 20 | function getHistoryFilePath(): string | null { |
| 21 | const shell = process.env.SHELL || ""; |
| 22 | const home = os.homedir(); |
| 23 | const isWindows = process.platform === "win32"; |
| 24 | |
| 25 | // Windows: Prefer PowerShell PSReadLine history if available |
| 26 | if (isWindows) { |
| 27 | const appData = |
| 28 | process.env.APPDATA || path.join(home, "AppData", "Roaming"); |
| 29 | const psHistoryCandidates = [ |
| 30 | // Windows PowerShell 5.x |
| 31 | path.join( |
| 32 | appData, |
| 33 | "Microsoft", |
| 34 | "Windows", |
| 35 | "PowerShell", |
| 36 | "PSReadLine", |
| 37 | "ConsoleHost_history.txt" |
| 38 | ), |
| 39 | // PowerShell 7+ |
| 40 | path.join( |
| 41 | appData, |
| 42 | "Microsoft", |
| 43 | "PowerShell", |
| 44 | "PSReadLine", |
| 45 | "ConsoleHost_history.txt" |
| 46 | ), |
| 47 | ]; |
| 48 | for (const psPath of psHistoryCandidates) { |
| 49 | if (fs.existsSync(psPath)) return psPath; |
| 50 | } |
| 51 | // If nothing found on Windows, fall through to shared fallbacks that may exist under Git Bash, MSYS, or Cygwin |
| 52 | } |
| 53 | |
| 54 | if (shell.includes("zsh")) { |
| 55 | return process.env.HISTFILE || path.join(home, ".zsh_history"); |
| 56 | } else if (shell.includes("bash")) { |
| 57 | return process.env.HISTFILE || path.join(home, ".bash_history"); |
| 58 | } else if (shell.includes("fish")) { |
| 59 | const macFish = path.join( |
| 60 | home, |
| 61 | "Library", |
| 62 | "Application Support", |
| 63 | "fish", |
| 64 | "fish_history" |
| 65 | ); |
| 66 | const linuxFish = path.join( |
| 67 | home, |
| 68 | ".local", |
| 69 | "share", |
| 70 | "fish", |
| 71 | "fish_history" |
| 72 | ); |
| 73 | if (fs.existsSync(macFish)) return macFish; |
| 74 | return linuxFish; |
| 75 | } |
| 76 | |
| 77 | // Try common paths as fallback |