add xdg env check

This commit is contained in:
Tomasz Kapias 2023-03-19 15:38:34 +07:00
parent ac5ce1fbe6
commit 6a15c81069
Signed by: tkapias
SSH key fingerprint: SHA256:bsmasrX7y0xxAHa/x1x8zAgHInO4nPpKMk5JIQ0Vsbw

View file

@ -23,26 +23,28 @@ if [[ -d "$HOME/.local/bin" ]] ; then
fi fi
# Check if XDG environment variables are set or set them to default # Check if XDG environment variables are set or set them to default
if [[ -z "$XDG_DATA_HOME" ]]; then if command -v xdg-user-dir 1> /dev/null; then
if [[ -z "$XDG_DATA_HOME" ]]; then
export XDG_DATA_HOME=$HOME/.local/share export XDG_DATA_HOME=$HOME/.local/share
fi fi
if [[ -z "$XDG_CONFIG_HOME" ]]; then if [[ -z "$XDG_CONFIG_HOME" ]]; then
export XDG_CONFIG_HOME=$HOME/.config export XDG_CONFIG_HOME=$HOME/.config
fi fi
if [[ -z "$XDG_STATE_HOME" ]]; then if [[ -z "$XDG_STATE_HOME" ]]; then
export XDG_STATE_HOME=$HOME/.local/state export XDG_STATE_HOME=$HOME/.local/state
fi fi
if [[ -z "$XDG_CACHE_HOME" ]]; then if [[ -z "$XDG_CACHE_HOME" ]]; then
export XDG_CACHE_HOME=$HOME/.cache export XDG_CACHE_HOME=$HOME/.cache
fi fi
# Check presence of locale Download folder or create a default one # Check presence of locale Download folder or create a default one
if [[ "$(xdg-user-dir DOWNLOAD)" == "$(xdg-user-dir)" ]]; then if [[ "$(xdg-user-dir DOWNLOAD)" == "$(xdg-user-dir)" ]]; then
mkdir -p "$HOME/Downloads" mkdir -p "$HOME/Downloads"
export XDG_DOWNLOAD_DIR="$HOME/Downloads" export XDG_DOWNLOAD_DIR="$HOME/Downloads"
else else
XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)" XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)"
export XDG_DOWNLOAD_DIR export XDG_DOWNLOAD_DIR
fi
fi fi
# ============================== # ==============================