From 3a29962a4bfcb0cf6cdfd112fb87f68751b0a0dc Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 15 Dec 2020 15:16:35 +0300 Subject: [PATCH] Relative paths to targets in outside directories --- README | 2 +- run.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README b/README index 0cdf3ca..0cb969a 100644 --- a/README +++ b/README @@ -41,7 +41,7 @@ NOTES *goredo-notes* * "all" target is default * stdout is always captured, but no target is created if it was empty * empty targets are considered always out of date -* .do's $3 is relative path to the file in same directory +* .do's $3 is relative path to the file in target directory * .do search goes up to / by default, but can be limited with either $REDO_TOP_DIR environment variable, or by having .redo/top file in it * target's completion messages are written after they finish diff --git a/run.go b/run.go index c85543a..589889e 100644 --- a/run.go +++ b/run.go @@ -28,6 +28,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strings" "sync" "syscall" @@ -306,13 +307,22 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } // Temporary file for stdout - fdStdout, err := tempfile(cwd, tgt) + fdStdout, err := tempfile(cwdOrig, tgt) if err != nil { cleanup() return TgtErr{tgtOrig, err} } tmpPath := fdStdout.Name() + ".3" // and for $3 - args = append(args, tgt, basename, path.Base(tmpPath)) + tmpPathRel, err := filepath.Rel(cwd, tmpPath) + if err != nil { + panic(err) + } + args = append( + args, + path.Join(dirPrefix, tgt), + path.Join(dirPrefix, basename), + tmpPathRel, + ) cmd := exec.Command(cmdName, args...) cmd.Dir = cwd -- 2.44.0