Skip to content

Instantly share code, notes, and snippets.

@ymgyt
Last active May 30, 2017 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymgyt/7642d43690d803bd0e650416526f5f6c to your computer and use it in GitHub Desktop.
Save ymgyt/7642d43690d803bd0e650416526f5f6c to your computer and use it in GitHub Desktop.
func absPathify(inPath string) string {
if strings.HasPrefix(inPath, "$HOME") {
inPath = userHomeDir() + inPath[5:]
}
if strings.HasPrefix(inPath, "$") {
end := strings.Index(inPath, string(os.PathSeparator))
inPath = os.Getenv(inPath[1:end]) + inPath[end:]
}
if filepath.IsAbs(inPath) {
return filepath.Clean(inPath)
}
p, err := filepath.Abs(inPath)
if err == nil {
return filepath.Clean(p)
}
jww.ERROR.Println("Couldn't discover absolute path")
jww.ERROR.Println(err)
return ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment