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
This commit is contained in:
parent
dd71bd5002
commit
0d978f7673
2 changed files with 26 additions and 12 deletions
|
@ -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
|
# non-standard, is added to path to enable execution of any files herein
|
||||||
test "$XDG_BIN_HOME" || export XDG_BIN_HOME="$HOME/.local/bin"
|
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
|
## ensure directories exist
|
||||||
test -d "$XDG_BIN_HOME" || mkdir -p -m 0700 "$XDG_BIN_HOME"
|
xdg_isThere "$XDG_BIN_HOME" || xdg_makeForUser "$XDG_BIN_HOME"
|
||||||
test -d "$XDG_CACHE_HOME" || mkdir -p -m 0700 "$XDG_CACHE_HOME"
|
xdg_isThere "$XDG_CACHE_HOME" || xdg_makeForUser "$XDG_CACHE_HOME"
|
||||||
test -d "$XDG_CONFIG_HOME" || mkdir -p -m 0700 "$XDG_CONFIG_HOME"
|
xdg_isThere "$XDG_CONFIG_HOME" || xdg_makeForUser "$XDG_CONFIG_HOME"
|
||||||
test -d "$XDG_DATA_HOME" || mkdir -p -m 0700 "$XDG_DATA_HOME"
|
xdg_isThere "$XDG_DATA_HOME" || xdg_makeForUser "$XDG_DATA_HOME"
|
||||||
|
|
||||||
# create xdg-user-dirs if necessary
|
# create xdg-user-dirs if necessary
|
||||||
test -d "$XDG_DESKTOP_DIR" || mkdir -p -m 0700 "$XDG_DESKTOP_DIR"
|
xdg_isThere "$XDG_DESKTOP_DIR" || xdg_makeForUser "$XDG_DESKTOP_DIR"
|
||||||
test -d "$XDG_DOCUMENTS_DIR" || mkdir -p -m 0700 "$XDG_DOCUMENTS_DIR"
|
xdg_isThere "$XDG_DOCUMENTS_DIR" || xdg_makeForUser "$XDG_DOCUMENTS_DIR"
|
||||||
test -d "$XDG_DOWNLOAD_DIR" || mkdir -p -m 0700 "$XDG_DOWNLOAD_DIR"
|
xdg_isThere "$XDG_DOWNLOAD_DIR" || xdg_makeForUser "$XDG_DOWNLOAD_DIR"
|
||||||
test -d "$XDG_MUSIC_DIR" || mkdir -p -m 0700 "$XDG_MUSIC_DIR"
|
xdg_isThere "$XDG_MUSIC_DIR" || xdg_makeForUser "$XDG_MUSIC_DIR"
|
||||||
test -d "$XDG_PICTURES_DIR" || mkdir -p -m 0700 "$XDG_PICTURES_DIR"
|
xdg_isThere "$XDG_PICTURES_DIR" || xdg_makeForUser "$XDG_PICTURES_DIR"
|
||||||
test -d "$XDG_PROJECTS_DIR" || mkdir -p -m 0700 "$XDG_PROJECTS_DIR"
|
xdg_isThere "$XDG_PROJECTS_DIR" || xdg_makeForUser "$XDG_PROJECTS_DIR"
|
||||||
test -d "$XDG_VIDEOS_DIR" || mkdir -p -m 0700 "$XDG_VIDEOS_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
|
## Applications that can be set through environment variables
|
||||||
export NVM_DIR="$XDG_DATA_HOME/nvm"
|
export NVM_DIR="$XDG_DATA_HOME/nvm"
|
||||||
|
|
|
@ -118,7 +118,6 @@ set findprg='fd %A --hidden --exclude .git --exclude node_modules'
|
||||||
mark h ~/
|
mark h ~/
|
||||||
mark d ~/downloads/
|
mark d ~/downloads/
|
||||||
mark p ~/projects/
|
mark p ~/projects/
|
||||||
mark s ~/projects/studentassistant/
|
|
||||||
mark i ~/pictures/
|
mark i ~/pictures/
|
||||||
mark v ~/videos/
|
mark v ~/videos/
|
||||||
mark n ~/documents/notes/
|
mark n ~/documents/notes/
|
||||||
|
|
Loading…
Reference in a new issue