https://github.com/atrox/homedir
Go library for detecting and expanding the user's home directory
https://github.com/atrox/homedir
golang home-directory homedir
Last synced: 6 months ago
JSON representation
Go library for detecting and expanding the user's home directory
- Host: GitHub
- URL: https://github.com/atrox/homedir
- Owner: Atrox
- License: mit
- Created: 2017-10-10T08:59:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-11T10:29:15.000Z (over 8 years ago)
- Last Synced: 2024-10-14T09:32:21.412Z (about 1 year ago)
- Topics: golang, home-directory, homedir
- Language: Go
- Size: 1.95 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HomeDir
[](https://travis-ci.org/Atrox/homedir)
[](https://coveralls.io/r/Atrox/homedir)
[](https://goreportcard.com/report/github.com/atrox/homedir)
[](https://godoc.org/github.com/Atrox/homedir)
> This library is based on and fully compatible with [mitchellh/go-homedir](https://github.com/mitchellh/go-homedir) but uses `os/user` because since go 1.9 there is no longer cgo compilation required.
## Installation
```sh
go get -u github.com/atrox/homedir
# or with dep
dep ensure -add github.com/atrox/homedir
```
## Usage
Usage is incredibly simple, just call `homedir.Dir()` to get the home directory
for a user, and `homedir.Expand(path string)` to expand the `~` in a path to the home
directory.
## Example
```go
package main
import (
"fmt"
"github.com/atrox/homedir"
)
func main() {
dir, err := homedir.Dir()
if err != nil {
panic(err)
}
fmt.Printf("'%s' is your users home directory\n", dir)
path, err := homedir.Expand("~/.config")
if err != nil {
panic(err)
}
fmt.Printf("'%s' is the expanded path to the .config directory\n", path)
}
```
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/atrox/homedir/issues)
- Fix bugs and [submit pull requests](https://github.com/atrox/homedir/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features