dotfiles/sh/.config/sh/xdg
Marty Oehme bcd90e7048
sh: Fix mkdir issue after removing XDG env vars
Fixed bug introduced in 15f5f0b when removing the environment variable
for two XDG directories, but not their creation.
The test would check an empty directory for its existence and, not
finding '' to be a directory, attempt to create it instead - resulting
in the attempt to create a directory of an empty string.
2021-03-22 21:05:15 +01:00

54 lines
2.5 KiB
Bash

#!/usr/bin/env sh
# XDG Base Directory Specification
#
# Sets up necessary environment variables for XDG convention,
# and those that applications obey for their environments.
#
# Thank you remeberYou for the idea
# see: https://github.com/rememberYou/dotfiles/blob/master/sh/.config/sh/xdg
#
# Additionally, home directories are set using the XDG specification,
# if the xdg-user-dirs module is enabled.
#
# Shellcheck will complain about setting permissions for the directories
# unless it is ignored https://github.com/koalaman/shellcheck/wiki/SC2174
# shellcheck disable=SC2174
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
test "$XDG_CACHE_HOME" || export XDG_CACHE_HOME="$HOME/.cache"
test "$XDG_CONFIG_HOME" || export XDG_CONFIG_HOME="$HOME/.config"
test "$XDG_DATA_HOME" || export XDG_DATA_HOME="$HOME/.local/share"
# Desktop environment XDG variables - mimics `xdg-user-dirs` settings, only lowercased and not localized
test "$XDG_DESKTOP_DIR" || export XDG_DESKTOP_DIR="$HOME/desktop"
test "$XDG_DOCUMENTS_DIR" || export XDG_DOCUMENTS_DIR="$HOME/documents"
test "$XDG_DOWNLOAD_DIR" || export XDG_DOWNLOAD_DIR="$HOME/downloads"
test "$XDG_MUSIC_DIR" || export XDG_MUSIC_DIR="$HOME/music"
test "$XDG_PICTURES_DIR" || export XDG_PICTURES_DIR="$HOME/pictures"
test "$XDG_PROJECTS_DIR" || export XDG_PROJECTS_DIR="$HOME/projects"
test "$XDG_VIDEOS_DIR" || export XDG_VIDEOS_DIR="$HOME/videos"
## Non-Standard additions
# non-standard, is added to path to enable execution of any files herein
test "$XDG_BIN_HOME" || export XDG_BIN_HOME="$HOME/.local/bin"
## ensure directories exist
test -d "$XDG_BIN_HOME" || mkdir -p -m 0700 "$XDG_BIN_HOME"
test -d "$XDG_CACHE_HOME" || mkdir -p -m 0700 "$XDG_CACHE_HOME"
test -d "$XDG_CONFIG_HOME" || mkdir -p -m 0700 "$XDG_CONFIG_HOME"
test -d "$XDG_DATA_HOME" || mkdir -p -m 0700 "$XDG_DATA_HOME"
# create xdg-user-dirs if necessary
test -d "$XDG_DESKTOP_DIR" || mkdir -p -m 0700 "$XDG_DESKTOP_DIR"
test -d "$XDG_DOCUMENTS_DIR" || mkdir -p -m 0700 "$XDG_DOCUMENTS_DIR"
test -d "$XDG_DOWNLOAD_DIR" || mkdir -p -m 0700 "$XDG_DOWNLOAD_DIR"
test -d "$XDG_MUSIC_DIR" || mkdir -p -m 0700 "$XDG_MUSIC_DIR"
test -d "$XDG_PICTURES_DIR" || mkdir -p -m 0700 "$XDG_PICTURES_DIR"
test -d "$XDG_PROJECTS_DIR" || mkdir -p -m 0700 "$XDG_PROJECTS_DIR"
test -d "$XDG_VIDEOS_DIR" || mkdir -p -m 0700 "$XDG_VIDEOS_DIR"
## Applications that can be set through environment variables
export NVM_DIR="$XDG_DATA_HOME/nvm"
export TMUX_PLUGIN_MANAGER_PATH="$XDG_DATA_HOME/tmux"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"