Every desktop program has a magic folder.
GIMP has scripts. Obsidian has plugins, themes, and snippets. Some programs use .config. Some use .local/share. On Windows, some use AppData, some pretend they are Unix, and some do both.
So the real command is often simple:
cp thing "$somewhere"
The annoying part is remembering somewhere.
Today I wanted to install a GIMP Script-Fu file. The working IDPhoto script was in:
$HOME/.local/share/gimp/2.8/scripts
So I made the smallest possible solution:
# dirs.env
gimp_scripts="$HOME/.local/share/gimp/2.8/scripts"
obsidian_vault="$HOME/Documents/Obsidian"
obsidian_plugins="$obsidian_vault/.obsidian/plugins"
obsidian_themes="$obsidian_vault/.obsidian/themes"
obsidian_snippets="$obsidian_vault/.obsidian/snippets"
Then install with:
. ./dirs.env
cp a4-two-card-layers.scm "$gimp_scripts/"
That is the entire trick.
Not a package manager. Not an installer. Not a sync tool. Not a framework. Just a little file of named directories.
This:
cp script.scm "$gimp_scripts/"
says what I mean.
This:
cp script.scm "$HOME/.local/share/gimp/2.8/scripts/"
says what GIMP happens to require on this machine.
The second command is correct, but it is not memorable. It also becomes wrong when the application version changes, the OS changes, or the program decides to move its files again.
With dirs.env, the messy part is named once.
install-dirs.sh?I considered this:
install_to() {
mkdir -p "$1"
cp "$2" "$1/"
}
Then:
install_to "$gimp_scripts" a4-two-card-layers.scm
But honestly, cp already works. The function adds almost nothing.
The path is the useful thing. The install command is usually obvious.
So dirs.env is better than install-dirs.sh unless I actually need logic.
Yes, in adjacent forms.
This is not a new invention. It is a small personal version of several older ideas:
.env files: keep environment-specific values outside code..profile, .bashrc, .zshrc.XDG_DATA_HOME, XDG_CONFIG_HOME, and XDG_CACHE_HOME define where user files should live.direnv: automatically loads environment variables depending on the current directory.The difference is scope.
dirs.env is not trying to standardize the world. It is just my address book for program folders.
# dirs.env
name_of_place="/actual/path/to/place"
Use:
. ./dirs.env
cp file "$name_of_place/"
That is it.
Use shell-safe names:
gimp_scripts=...
obsidian_plugins=...
Not:
current-gimp-scripts=...
Shell variables cannot contain hyphens.
dirs.env?Good candidates:
gimp_scripts="$HOME/.local/share/gimp/2.8/scripts"
obsidian_plugins="$obsidian_vault/.obsidian/plugins"
obsidian_themes="$obsidian_vault/.obsidian/themes"
obsidian_snippets="$obsidian_vault/.obsidian/snippets"
Maybe:
fonts="$HOME/.local/share/fonts"
bin="$HOME/.local/bin"
desktop_files="$HOME/.local/share/applications"
Do not put secrets here. This is not a password manager.
Source: https://specifications.freedesktop.org/basedir-spec/latest/
Notes:
XDG_DATA_HOMEXDG_CONFIG_HOMEXDG_STATE_HOMEXDG_CACHE_HOMEXDG_RUNTIME_DIRdirs.env is much less ambitious. It can point to XDG-derived locations, but it also handles app-specific subfolders like GIMP scripts or Obsidian snippets.Source: https://direnv.net/
Notes:
direnv loads and unloads environment variables based on the current directory..envrc.dirs.env is manual and dumb by comparison. That is a feature here. No hook, no authorization flow, no shell integration.Source: https://12factor.net/config
Notes:
dirs.env borrows the same basic move: names outside commands/code, values change per machine.dirs.env: my address book for application folderscp plus dirs.env.env file for install directoriesAPPDATA if needed.Make a file:
gimp_scripts="$HOME/.local/share/gimp/2.8/scripts"
Use it:
. ./dirs.env
cp script.scm "$gimp_scripts/"
Small trick. Big reduction in path remembering.