Build StatusLFE VersionsErlang VersionsTags

Project Logo

dirs

A port of the Rust dirs library to LFE/Erlang

Introduction

The library provides the location of these directories by leveraging the mechanisms defined by

Platforms

This library is written in LFE but can be used transparently in Erlang or Elixir projects (that support rebar3) as if it was an Erlang library. It supports Linux, Redox, macOS and Windows. Other platforms are also supported; they use the Linux conventions.

Usage

Library run by user alice in Erlang:

1> dirs:home();
%% Lin: /home/alice
%% Win: C:\Users\Alice
%% Mac: /Users/Alice
2> dirs:audio();
%% Lin: /home/alice/Music
%% Win: C:\Users\Alice\Music
%% Mac: /Users/Alice/Music
3> dirs:config();
%% Lin: /home/alice/.config
%% Win: C:\Users\Alice\AppData\Roaming
%% Mac: /Users/Alice/Library/Application Support
4> dirs:executable();
%% Lin: /home/alice/.local/bin
%% Win: undefined
%% Mac: undefined

In LFE:

lfe> (dirs:home)
;; Lin: /home/alice
;; Win: C:\Users\Alice
;; Mac: /Users/Alice
lfe> (dirs:audio)
;; Lin: /home/alice/Music
;; Win: C:\Users\Alice\Music
;; Mac: /Users/Alice/Music
lfe> (dirs:config)
;; Lin: /home/alice/.config
;; Win: C:\Users\Alice\AppData\Roaming
;; Mac: /Users/Alice/Library/Application Support
lfe> (dirs:executable)
;; Lin: /home/alice/.local/bin
;; Win: undefined
;; Mac: undefined

Design Goals

Features

Function nameValue on Linux/RedoxValue on WindowsValue on macOS
dirs:home$HOME{FOLDERID_Profile}$HOME
dirs:cache$XDG_CACHE_HOME or $HOME/.cache{FOLDERID_LocalAppData}$HOME/Library/Caches
dirs:config$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_RoamingAppData}$HOME/Library/Application Support
dirs:config_local and dirs:config-local$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_LocalAppData}$HOME/Library/Application Support
dirs:data$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_RoamingAppData}$HOME/Library/Application Support
dirs:data_local and dirs::data-local$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_LocalAppData}$HOME/Library/Application Support
dirs:executable$XDG_BIN_HOME or $HOME/.local/binundefinedundefined
dirs:preference$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_RoamingAppData}$HOME/Library/Preferences
dirs:runtime$XDG_RUNTIME_DIR or undefinedundefinedundefined
dirs:state$XDG_STATE_HOME or $HOME/.local/stateundefinedundefined
dirs:audioXDG_MUSIC_DIR or undefined{FOLDERID_Music}$HOME/Music
dirs:desktopXDG_DESKTOP_DIR or undefined{FOLDERID_Desktop}$HOME/Desktop
dirs:documentXDG_DOCUMENTS_DIR or undefined{FOLDERID_Documents}$HOME/Documents
dirs:downloadXDG_DOWNLOAD_DIR or undefined{FOLDERID_Downloads}$HOME/Downloads
dirs:font$XDG_DATA_HOME/fonts or $HOME/.local/share/fontsundefined$HOME/Library/Fonts
dirs:pictureXDG_PICTURES_DIR or undefined{FOLDERID_Pictures}$HOME/Pictures
dirs:publicXDG_PUBLICSHARE_DIR or undefined{FOLDERID_Public}$HOME/Public
dirs:templateXDG_TEMPLATES_DIR or undefined{FOLDERID_Templates}undefined
dirs:videoXDG_VIDEOS_DIR or undefined{FOLDERID_Videos}$HOME/Movies

License

Apache License, Version 2.0

Copyright © 2023, Duncan McGreggor oubiwann@gmail.com.