feat(v0.5.3): ResolveSessionMode env var resolver

This commit is contained in:
2026-05-08 13:47:49 -04:00
parent 32fa5d0d21
commit 120dc54337
2 changed files with 80 additions and 0 deletions
+20
View File
@@ -1,6 +1,7 @@
package config
import (
"fmt"
"os"
"path/filepath"
"runtime"
@@ -148,6 +149,25 @@ func defaultSeedDir(leaf string) string {
return filepath.Join(home, ".config", "ctask", leaf)
}
// ResolveSessionMode returns "direct" or "persistent" based on CTASK_SESSION_MODE.
// Default (unset/empty) is "direct". Any other value falls back to "direct"
// after printing a stderr warning. Used by entry commands (new, resume, last,
// open) to dispatch between the standard session.Run path and the tmux-backed
// persistent path.
func ResolveSessionMode() string {
v := os.Getenv("CTASK_SESSION_MODE")
switch v {
case "", "direct":
return "direct"
case "persistent":
return "persistent"
default:
fmt.Fprintf(os.Stderr,
"[ctask] warning: CTASK_SESSION_MODE=%q is not recognized; using direct mode\n", v)
return "direct"
}
}
// expandPath expands a leading ~/ and resolves to an absolute path when possible.
func expandPath(p string) string {
if strings.HasPrefix(p, "~/") || p == "~" {