github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/pkg/homedir/homedir_unix.go (about)

     1  // +build !windows
     2  
     3  package homedir // import "github.com/docker/docker/pkg/homedir"
     4  
     5  import (
     6  	"os"
     7  
     8  	"github.com/opencontainers/runc/libcontainer/user"
     9  )
    10  
    11  // Key returns the env var name for the user's home dir based on
    12  // the platform being run on
    13  func Key() string {
    14  	return "HOME"
    15  }
    16  
    17  // Get returns the home directory of the current user with the help of
    18  // environment variables depending on the target operating system.
    19  // Returned path should be used with "path/filepath" to form new paths.
    20  func Get() string {
    21  	home := os.Getenv(Key())
    22  	if home == "" {
    23  		if u, err := user.CurrentUser(); err == nil {
    24  			return u.Home
    25  		}
    26  	}
    27  	return home
    28  }
    29  
    30  // GetShortcutString returns the string that is shortcut to user's home directory
    31  // in the native shell of the platform running on.
    32  func GetShortcutString() string {
    33  	return "~"
    34  }