Standard library · System and tools

os/user

Who is running the program, and the standard directories that belong to them.

import os.user
On this page
  1. Functions

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(): str
The name of the current user.
os-user-Username.salam
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
end
Outputtrue true true true true true

Uid

func Uid(): int
The 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(): int
The 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(): str
The home directory of the user.

The example for this item is shown with the ones above: os-user-Username.salam

ConfigDir

func ConfigDir(): str
The standard directory for program settings.

The example for this item is shown with the ones above: os-user-Username.salam

CacheDir

func CacheDir(): str
The standard directory for program caches.

The example for this item is shown with the ones above: os-user-Username.salam