-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand environment variables on "dir", "sources" and "generates"
So a path like this works: $GOPATH/src/github.com/go-task/task Allowing of "~" was also implemented. See #74 and baac067 Fixes #116
- Loading branch information
1 parent
a830dba
commit 102f8ab
Showing
4 changed files
with
28 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
andreynering
Author
Member
|
||
s = os.ExpandEnv(s) | ||
|
||
var err error | ||
s, err = homedir.Expand(s) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return s, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In case you didn't know, you can replace this with
mvdan.cc/sh/shell.Expand(s, nil)
:) It's likeos.ExpandEnv
, but it supports all the shell expansions you're used to. This includes complex parameter substitutions like${foo:-bar}
, but also~/foo
.