From 0d978f767389520c0577d67c199d9ffed2756d5f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 13 Apr 2021 09:17:54 +0200 Subject: [PATCH] sh: Update xdg directory auto creation Improved the automatic directory creation somewhat: It now looks for either a file existing there (could be a directory, could be an actual file), or a symbolic link pointing somewhere else. Only if none of those things are at the xdg location will it try to create a new directory there. Additionally, it will set the correct permissions for the whole folder chain being created, NOT just for the last folder in the chain. vifm: Switch to new xdg directory structure --- sh/.config/sh/xdg | 37 ++++++++++++++++++++++++++----------- vifm/.config/vifm/vifmrc | 1 - 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/sh/.config/sh/xdg b/sh/.config/sh/xdg index cc00e45..a018ca3 100644 --- a/sh/.config/sh/xdg +++ b/sh/.config/sh/xdg @@ -32,20 +32,35 @@ test "$XDG_VIDEOS_DIR" || export XDG_VIDEOS_DIR="$HOME/videos" # non-standard, is added to path to enable execution of any files herein test "$XDG_BIN_HOME" || export XDG_BIN_HOME="$HOME/.local/bin" +xdg_isThere() { + if [ -e "$1" ] || [ -h "$1" ]; then + true + else + false + fi +} + +xdg_makeForUser() { + mkdir -p "$1" + chmod 0700 "$1" +} + ## 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" +xdg_isThere "$XDG_BIN_HOME" || xdg_makeForUser "$XDG_BIN_HOME" +xdg_isThere "$XDG_CACHE_HOME" || xdg_makeForUser "$XDG_CACHE_HOME" +xdg_isThere "$XDG_CONFIG_HOME" || xdg_makeForUser "$XDG_CONFIG_HOME" +xdg_isThere "$XDG_DATA_HOME" || xdg_makeForUser "$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" +xdg_isThere "$XDG_DESKTOP_DIR" || xdg_makeForUser "$XDG_DESKTOP_DIR" +xdg_isThere "$XDG_DOCUMENTS_DIR" || xdg_makeForUser "$XDG_DOCUMENTS_DIR" +xdg_isThere "$XDG_DOWNLOAD_DIR" || xdg_makeForUser "$XDG_DOWNLOAD_DIR" +xdg_isThere "$XDG_MUSIC_DIR" || xdg_makeForUser "$XDG_MUSIC_DIR" +xdg_isThere "$XDG_PICTURES_DIR" || xdg_makeForUser "$XDG_PICTURES_DIR" +xdg_isThere "$XDG_PROJECTS_DIR" || xdg_makeForUser "$XDG_PROJECTS_DIR" +xdg_isThere "$XDG_VIDEOS_DIR" || xdg_makeForUser "$XDG_VIDEOS_DIR" + +unset -f xdg_isThere xdg_makeForUser ## Applications that can be set through environment variables export NVM_DIR="$XDG_DATA_HOME/nvm" diff --git a/vifm/.config/vifm/vifmrc b/vifm/.config/vifm/vifmrc index 811d889..483245b 100644 --- a/vifm/.config/vifm/vifmrc +++ b/vifm/.config/vifm/vifmrc @@ -118,7 +118,6 @@ set findprg='fd %A --hidden --exclude .git --exclude node_modules' mark h ~/ mark d ~/downloads/ mark p ~/projects/ -mark s ~/projects/studentassistant/ mark i ~/pictures/ mark v ~/videos/ mark n ~/documents/notes/