os/user
Who is running the program, and the standard directories that belong to them.
import os.user
On this page
Programs usually keep their settings in the user config directory and throwaway data in the user cache directory. This package gives the right path on every operating system; the config directory is ~/.config on Linux and somewhere else on macOS and Windows.
Functions
Username
func Username(): strThe name of the current user.
import os.user
func main:
println user.Username().len() > 0
println user.Uid() >= 0, user.Gid() >= 0
println user.HomeDir().len() > 0
println user.ConfigDir().len() > 0, user.CacheDir().len() > 0
endOutputtrue
true true
true
true true
Uid
func Uid(): intThe numeric user id; minus one on Windows.
The example for this item is shown with the ones above: os-user-Username.salam
Gid
func Gid(): intThe numeric group id of the user; minus one on Windows.
The example for this item is shown with the ones above: os-user-Username.salam
HomeDir
func HomeDir(): strThe home directory of the user.
The example for this item is shown with the ones above: os-user-Username.salam
ConfigDir
func ConfigDir(): strThe standard directory for program settings.
The example for this item is shown with the ones above: os-user-Username.salam
CacheDir
func CacheDir(): strThe standard directory for program caches.
The example for this item is shown with the ones above: os-user-Username.salam