Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

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:

About

Go library for detecting and expanding the user's home directory

Topics

Resources

License

Packages

No packages published

Languages