Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.73 KB

README.md

File metadata and controls

57 lines (42 loc) · 1.73 KB

HomeDir

Build Status Coverage Status Go Report Card GoDoc

This library is based on and fully compatible with mitchellh/go-homedir but uses os/user because since go 1.9 there is no longer cgo compilation required.

Installation

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

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: