From 6a15c8106948088b562a8903d965d7aa672e0837 Mon Sep 17 00:00:00 2001 From: Tomasz Kapias Date: Sun, 19 Mar 2023 15:38:34 +0700 Subject: [PATCH] add xdg env check --- .bashrc.d/01-env.bashrc | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/.bashrc.d/01-env.bashrc b/.bashrc.d/01-env.bashrc index 0bc2694..b860b84 100644 --- a/.bashrc.d/01-env.bashrc +++ b/.bashrc.d/01-env.bashrc @@ -23,26 +23,28 @@ if [[ -d "$HOME/.local/bin" ]] ; then fi # Check if XDG environment variables are set or set them to default -if [[ -z "$XDG_DATA_HOME" ]]; then - export XDG_DATA_HOME=$HOME/.local/share -fi -if [[ -z "$XDG_CONFIG_HOME" ]]; then - export XDG_CONFIG_HOME=$HOME/.config -fi -if [[ -z "$XDG_STATE_HOME" ]]; then - export XDG_STATE_HOME=$HOME/.local/state -fi -if [[ -z "$XDG_CACHE_HOME" ]]; then - export XDG_CACHE_HOME=$HOME/.cache -fi - -# Check presence of locale Download folder or create a default one -if [[ "$(xdg-user-dir DOWNLOAD)" == "$(xdg-user-dir)" ]]; then - mkdir -p "$HOME/Downloads" - export XDG_DOWNLOAD_DIR="$HOME/Downloads" -else - XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)" - export XDG_DOWNLOAD_DIR +if command -v xdg-user-dir 1> /dev/null; then + if [[ -z "$XDG_DATA_HOME" ]]; then + export XDG_DATA_HOME=$HOME/.local/share + fi + if [[ -z "$XDG_CONFIG_HOME" ]]; then + export XDG_CONFIG_HOME=$HOME/.config + fi + if [[ -z "$XDG_STATE_HOME" ]]; then + export XDG_STATE_HOME=$HOME/.local/state + fi + if [[ -z "$XDG_CACHE_HOME" ]]; then + export XDG_CACHE_HOME=$HOME/.cache + fi + + # Check presence of locale Download folder or create a default one + if [[ "$(xdg-user-dir DOWNLOAD)" == "$(xdg-user-dir)" ]]; then + mkdir -p "$HOME/Downloads" + export XDG_DOWNLOAD_DIR="$HOME/Downloads" + else + XDG_DOWNLOAD_DIR="$(xdg-user-dir DOWNLOAD)" + export XDG_DOWNLOAD_DIR + fi fi # ==============================