Dirs
Base and user directories.
The class methods return base directories:
require "dirs"
Dirs.config_home
# => Path["~/.config"] (UNIX)
# => Path["~/Library/Preferences"] (Darwin)
# => Path["~/AppData/Roaming"] (Windows)
Instantiate a Dirs object to resolve paths for your application:
require "directories"
app = Dirs::Project.new("foo")
app.config("settings.json")
# => Path["~/.config/foo/settings.json"] (UNIX)
# => Path["~/Library/Preferences/foo/settings.json"] (Darwin)
# => Path["~/AppData/Roaming/foo/config/settings.json"] (Windows)
Class methods
Path to the user's home bin directory. This is where executables can be
installed. The path should usually be in the user's PATH.
Uses $XDG_BIN_HOME when defined on UNIX.
- UNIX:
$HOME/.local/bin
WARNING: Not portable. The method is undefined on macOS and Windows (no such directory).
Path to the user's home cache directory. This is the directory where applications are expected to save local, ephemeral, files.
Uses $XDG_CACHE_HOME when defined on UNIX.
- UNIX:
$HOME/.cache - Darwin:
$HOME/Library/Caches - Windows:
%LOCALAPPDATA%or%USERPROFILE%\AppData\Local
Path to the user's home configuration directory. This is the directory where applications are expected to save their configuration.
Uses $XDG_CONFIG_HOME when defined on UNIX.
- UNIX:
$HOME/.config - Darwin:
$HOME/Library/Preferences - Windows:
%APPDATA%or%USERPROFILE%\AppData\Roaming
Path to the user's home data directory. This is where applications are expected to store downloaded or generated data.
Uses $XDG_DATA_HOME when defined on UNIX.
- UNIX:
$HOME/.local/share - Darwin:
$HOME/Library/Application Support - Windows:
%APPDATA%or%USERPROFILE%\AppData\Roaming
Path to the user's desktop directory.
Uses $XDG_DESKTOP_DIR or user-dirs on UNIX. Defaults to to
$HOME/Desktop.
Path to the user's documents directory.
Uses $XDG_DOCUMENTS_DIR or user-dirs on UNIX. Defaults to
$HOME/Documents.
Path to the user's downloads directory.
Uses $XDG_DOWNLOAD_DIR or user-dirs on UNIX. Defaults $HOME/Downloads.
Path to the user's music directory.
Uses $XDG_MUSIC_DIR or user-dirs on UNIX. Defaults to $HOME/Music.
Path to the user's pictures directory.
Uses $XDG_PICTURES_DIR or user-dirs on UNIX. Defaults to $HOME/Pictures.
Path to the user's runtime directory. This is where applications are expected to store data for the current execution, such as UNIX sockets or pid files.
Uses $XDG_RUNTIME_DIR on UNIX. There are no defaults. The value should
be automatically set by the OS on UNIX systems. For example
/run/user/1000 where 1000 is the user id (UID).
WARNING: Not portable. The method is undefined on macOS and Windows (no such directory).
Path to the user's home state directory. This is the directory where applications are expected to store their state across multiple executions, such as the last known state, history and logs.
Uses $XDG_STATE_HOME when defined on UNIX.
- UNIX:
$HOME/.local/state - Darwin:
$HOME/Library/State - Windows:
%LOCALAPPDATA%or%USERPROFILE%\AppData\Local
Path to the user's templates directory.
Uses $XDG_TEMPLATES_DIR or user-dirs on UNIX. Defaults to $HOME/Templates.
WARNING: Not portable. The method is undefined on macOS (no such directory).
Path to the user's videos directory.
Uses $XDG_VIDEOS_DIR or user-dirs on UNIX. Defaults to $HOME/Movies on
macOS and $HOME/Videos otherwise.