Explorar o código

fix: windows fallback for "less" cmd in `session list` (#6515)

Mani Sundararajan hai 3 meses
pai
achega
154c52c4d9
Modificáronse 1 ficheiros con 30 adicións e 1 borrados
  1. 30 1
      packages/opencode/src/cli/cmd/session.ts

+ 30 - 1
packages/opencode/src/cli/cmd/session.ts

@@ -4,7 +4,36 @@ import { Session } from "../../session"
 import { bootstrap } from "../bootstrap"
 import { UI } from "../ui"
 import { Locale } from "../../util/locale"
+import { Flag } from "../../flag/flag"
 import { EOL } from "os"
+import path from "path"
+
+function pagerCmd(): string[] {
+  const lessOptions = ["-R", "-S"]
+  if (process.platform !== "win32") {
+    return ["less", ...lessOptions]
+  }
+
+  // user could have less installed via other options
+  const lessOnPath = Bun.which("less")
+  if (lessOnPath) {
+    if (Bun.file(lessOnPath).size) return [lessOnPath, ...lessOptions]
+  }
+
+  if (Flag.OPENCODE_GIT_BASH_PATH) {
+    const less = path.join(Flag.OPENCODE_GIT_BASH_PATH, "..", "..", "usr", "bin", "less.exe")
+    if (Bun.file(less).size) return [less, ...lessOptions]
+  }
+
+  const git = Bun.which("git")
+  if (git) {
+    const less = path.join(git, "..", "..", "usr", "bin", "less.exe")
+    if (Bun.file(less).size) return [less, ...lessOptions]
+  }
+
+  // Fall back to Windows built-in more (via cmd.exe)
+  return ["cmd", "/c", "more"]
+}
 
 export const SessionCommand = cmd({
   command: "session",
@@ -58,7 +87,7 @@ export const SessionListCommand = cmd({
 
       if (shouldPaginate) {
         const proc = Bun.spawn({
-          cmd: ["less", "-R", "-S"],
+          cmd: pagerCmd(),
           stdin: "pipe",
           stdout: "inherit",
           stderr: "inherit",