Add CHANGELOG and improvements to #887

This commit is contained in:
Andrey Nering
2022-10-14 19:48:45 -03:00
parent 80b417c4ab
commit 44aa2ee3b3
3 changed files with 20 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package filepathext
import (
"os"
"path/filepath"
)
@@ -12,3 +13,19 @@ func SmartJoin(a, b string) string {
}
return filepath.Join(a, b)
}
// TryAbsToRel tries to convert an absolute path to relative based on the
// process working directory. If it can't, it returns the absolute path.
func TryAbsToRel(abs string) string {
wd, err := os.Getwd()
if err != nil {
return abs
}
rel, err := filepath.Rel(wd, abs)
if err != nil {
return abs
}
return rel
}