Skip to content

Commit 4138f6d

Browse files
committed
fix(cmd): inject unirtm dir into PATH for tasks and exec, add untrusted config hint
1 parent b0447ed commit 4138f6d

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

cmd/23.exec.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"runtime"
1213
"strings"
1314
"syscall"
@@ -307,13 +308,23 @@ func runExec(cmd *cobra.Command, args []string) error {
307308
// ── 6. Ensure tool binaries take precedence over shims ────────────────────
308309

309310
shimsDir := env.GetShimsDir()
311+
exePath, err := os.Executable()
312+
exeDir := ""
313+
if err == nil {
314+
exeDir = filepath.Dir(exePath)
315+
}
316+
310317
// Tool bins are already in additionalEnv["PATH"]. We want them to be searched FIRST.
311-
// Then shims, then the original system PATH.
318+
// Then shims, then the unirtm binary directory, then the original system PATH.
312319
if existing := additionalEnv["PATH"]; existing != "" {
313320
additionalEnv["PATH"] = existing + string(os.PathListSeparator) + shimsDir
314321
} else {
315322
additionalEnv["PATH"] = shimsDir
316323
}
324+
325+
if exeDir != "" {
326+
additionalEnv["PATH"] += string(os.PathListSeparator) + exeDir
327+
}
317328

318329
// Apply all collected env overrides onto the current process.
319330
applyEnvMap(additionalEnv)

cmd/25.run.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"os"
10+
"path/filepath"
1011
"strings"
1112

1213
"github.com/pterm/pterm"
@@ -177,6 +178,13 @@ func runTaskCommand(cmd *cobra.Command, args []string) error {
177178

178179
// Safe PATH merging to avoid hardcoded colons and exponential explosion on Windows
179180
newPath := shimsDir + string(os.PathListSeparator) + env.Get("PATH")
181+
182+
// Also inject the directory of the current unirtm executable so scripts can find it
183+
exePath, err := os.Executable()
184+
if err == nil {
185+
exeDir := filepath.Dir(exePath)
186+
newPath = shimsDir + string(os.PathListSeparator) + exeDir + string(os.PathListSeparator) + env.Get("PATH")
187+
}
180188

181189
// Deduplicate inline to keep PATH clean
182190
cleanPath := envpath.DeduplicateOSPaths(newPath)
@@ -193,6 +201,19 @@ func runTaskCommand(cmd *cobra.Command, args []string) error {
193201
// Execute task
194202
if err := engine.Execute(ctx, cwd, taskName, taskArgs, envInjects); err != nil {
195203
if strings.Contains(err.Error(), "no suitable task runner found") {
204+
// Check if local config is untrusted/modified and print a friendly hint
205+
tm := config.NewTrustManager()
206+
for _, f := range []string{".unirtm.toml", "unirtm.toml"} {
207+
p := filepath.Join(cwd, f)
208+
if _, err := os.Stat(p); err == nil {
209+
status := tm.TrustStatus(p)
210+
if status != config.TrustStatusTrusted {
211+
pterm.Warning.Printf("Tasks in %s are ignored because the configuration file is not trusted.\nPlease run 'unirtm trust' to enable them.\n\n", f)
212+
break
213+
}
214+
}
215+
}
216+
196217
// Suggest similar tasks or commands if not found
197218
var candidates []string
198219
for name := range cfg.Tasks {

0 commit comments

Comments
 (0)