install.sh: Honor XDG_DATA_HOME

[why]
When a user sets the XDG_DATA_HOME environment variable the default of
$HOME/.local/share should not be used.

https://wiki.archlinux.org/title/XDG_Base_Directory

[how]
Enable XDG_DATA_HOME to override the default user data directory on Unix
and MacOS platforms.

There is some controversy if XDG_DATA_HOME should be honored on MacOS,
see for example platformdirs (link below). But me also working on Linux
and MacOS (and Windows) in parallel, I can not quite follow the
downsides and believe we should allow XDG_DATA_HOME also for MacOS.

Related: https://github.com/platformdirs/platformdirs/issues/4
Fixes: #1324

Suggested-by: Anthony Foglia <@afoglia>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-07-28 08:53:46 +02:00 committed by Fini
parent 4b11f751a1
commit e398a3847c

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Install Nerd Fonts
__ScriptVersion="0.6"
__ScriptVersion="0.7"
# Default values for option variables:
quiet=false
@ -197,15 +197,20 @@ done
# Get target root directory
if [[ $(uname) == 'Darwin' ]]; then
# MacOS
sys_font_dir="/Library/Fonts"
usr_font_dir="$HOME/Library/Fonts"
sys_share_dir="/Library"
usr_share_dir="$HOME/Library"
font_subdir="Fonts"
else
# Linux
sys_font_dir="/usr/local/share/fonts"
usr_font_dir="$HOME/.local/share/fonts"
sys_share_dir="/usr/local/share"
usr_share_dir="$HOME/.local/share"
font_subdir="fonts"
fi
sys_font_dir="${sys_font_dir}/NerdFonts"
usr_font_dir="${usr_font_dir}/NerdFonts"
if [ -n "${XDG_DATA_HOME}" ]; then
usr_share_dir="${XDG_DATA_HOME}"
fi
sys_font_dir="${sys_share_dir}/${font_subdir}/NerdFonts"
usr_font_dir="${usr_share_dir}/${font_subdir}/NerdFonts"
if [[ "system" == "$installpath" ]]; then
font_dir="${sys_font_dir}"