dirs.env: named paths for where apps hide install folders

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.

Why this is nicer than remembering paths

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.

Why not write 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.

Has anyone had this idea?

Yes, in adjacent forms.

This is not a new invention. It is a small personal version of several older ideas:

The difference is scope.

dirs.env is not trying to standardize the world. It is just my address book for program folders.

Pattern

# dirs.env
name_of_place="/actual/path/to/place"

Use:

. ./dirs.env
cp file "$name_of_place/"

That is it.

Naming convention

Use shell-safe names:

gimp_scripts=...
obsidian_plugins=...

Not:

current-gimp-scripts=...

Shell variables cannot contain hyphens.

What belongs in 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.

Research notes

XDG Base Directory Specification

Source: https://specifications.freedesktop.org/basedir-spec/latest/

Notes:

direnv

Source: https://direnv.net/

Notes:

Twelve-Factor App config

Source: https://12factor.net/config

Notes:

Possible title ideas

TODO before publishing

Short version

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.