diff --git a/Taskfile.yml b/Taskfile.yml index 55aa7d76..d8a7e7ba 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -13,6 +13,7 @@ vars: ./internal/compiler/v2 ./internal/execext ./internal/logger + ./internal/osext ./internal/output ./internal/status ./internal/taskfile diff --git a/internal/osext/osext.go b/internal/osext/osext.go new file mode 100644 index 00000000..e6932e6a --- /dev/null +++ b/internal/osext/osext.go @@ -0,0 +1,22 @@ +package osext + +import ( + "os" + + "github.com/mitchellh/go-homedir" +) + +// Expand is an improved version of os.ExpandEnv, +// that not only expand enrionment variable ($GOPATH/src/github.com/...) +// but also expands "~" as the home directory. +func Expand(s string) (string, error) { + s = os.ExpandEnv(s) + + var err error + s, err = homedir.Expand(s) + if err != nil { + return "", err + } + + return s, nil +} diff --git a/internal/status/glob.go b/internal/status/glob.go index ef8e5c50..2bbe2ae4 100644 --- a/internal/status/glob.go +++ b/internal/status/glob.go @@ -4,8 +4,9 @@ import ( "path/filepath" "sort" + "github.com/go-task/task/internal/osext" + "github.com/mattn/go-zglob" - "github.com/mitchellh/go-homedir" ) func glob(dir string, globs []string) (files []string, err error) { @@ -13,7 +14,7 @@ func glob(dir string, globs []string) (files []string, err error) { if !filepath.IsAbs(g) { g = filepath.Join(dir, g) } - g, err = homedir.Expand(g) + g, err = osext.Expand(g) if err != nil { return nil, err } diff --git a/variables.go b/variables.go index e5d8b411..ce8a4127 100644 --- a/variables.go +++ b/variables.go @@ -3,10 +3,9 @@ package task import ( "path/filepath" + "github.com/go-task/task/internal/osext" "github.com/go-task/task/internal/taskfile" "github.com/go-task/task/internal/templater" - - "github.com/mitchellh/go-homedir" ) var ( @@ -41,7 +40,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { Method: r.Replace(origTask.Method), Prefix: r.Replace(origTask.Prefix), } - new.Dir, err = homedir.Expand(new.Dir) + new.Dir, err = osext.Expand(new.Dir) if err != nil { return nil, err }