mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-11 16:16:28 -04:00
Bumps [github.com/adrg/xdg](https://github.com/adrg/xdg) from 0.4.0 to 0.5.3. - [Release notes](https://github.com/adrg/xdg/releases) - [Commits](https://github.com/adrg/xdg/compare/v0.4.0...v0.5.3) --- updated-dependencies: - dependency-name: github.com/adrg/xdg dependency-version: 0.5.3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
41 lines
763 B
Go
41 lines
763 B
Go
package pathutil
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// UserHomeDir returns the home directory of the current user.
|
|
func UserHomeDir() string {
|
|
if home := os.Getenv("home"); home != "" {
|
|
return home
|
|
}
|
|
|
|
return "/"
|
|
}
|
|
|
|
// Exists returns true if the specified path exists.
|
|
func Exists(path string) bool {
|
|
_, err := os.Stat(path)
|
|
return err == nil || errors.Is(err, fs.ErrExist)
|
|
}
|
|
|
|
// ExpandHome substitutes `~` and `$home` at the start of the specified `path`.
|
|
func ExpandHome(path string) string {
|
|
home := UserHomeDir()
|
|
if path == "" || home == "" {
|
|
return path
|
|
}
|
|
if path[0] == '~' {
|
|
return filepath.Join(home, path[1:])
|
|
}
|
|
if strings.HasPrefix(path, "$home") {
|
|
return filepath.Join(home, path[5:])
|
|
}
|
|
|
|
return path
|
|
}
|