XDG desktop settings for M OS distros / Настройки рабочего окружения дистрибутивов М ОС
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mos-xdg/scripts/kometa-xdg-env

89 lines
2.5 KiB

#!/bin/sh
KOMETA_XDG_TESTING="${KOMETA_XDG_TESTING:-0}"
KOMETA_XDG_TYPE="${KOMETA_XDG_TYPE:-}"
KOMETA_XDG_DIR=/etc/xdg/kometa
XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-}"
_check_runability(){
case "$1" in
systemd ) : ;;
profile ) : ;;
* )
echo 'Set $KOMETA_XDG_TYPE to systemd or profile!' >&2
return 1
;;
esac
}
# XXX Who is that crazy person who sets adds ~/.config/kdedefaults to
# XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/kf5/xdg:/etc/xdg
# and why does he do such a strange thing?!
# Example of what we have to do:
# convert XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/kf5/xdg:/etc/xdg
# into XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/xdg/kometa:/etc/kf5/xdg:/etc/xdg
# I do not want to write very complex code to deal with all possible cases.
# Let's assume that current value:
# * is not a mess and is a valid value
# * does not have repeated directories (if it has, we will probably still be OK)
# $1: current value of $XDG_CONFIG_DIRS
_mk_xdg_config_dirs(){
local tmp
tmp="$1"
case "$tmp" in
"" )
# https://bugzilla.altlinux.org/show_bug.cgi?id=41566
tmp=/etc/kf5/xdg:/etc/xdg
;;
:/etc/xdg )
# not a valid value!
tmp=/etc/xdg
;;
/etc/xdg )
:
;;
*/etc/xdg )
:
;;
* )
# not a valid values - does not end with /etc/xdg
tmp="$tmp:/etc/xdg"
;;
esac
case "$tmp" in
*:/etc/xdg/kometa:* | /etc/xdg/kometa:* )
:
;;
*:/etc/kf5/xdg:* )
tmp="$(echo "$tmp" | sed -e "s,:/etc/kf5/xdg:,:$KOMETA_XDG_DIR:/etc/kf5/xdg:,")"
;;
/etc/kf5/xdg:* )
tmp="$(echo "$tmp" | sed -e "s,^/etc/kf5/xdg:,$KOMETA_XDG_DIR:/etc/kf5/xdg:,")"
;;
*:/etc/xdg )
tmp="$(echo "$tmp" | sed -e "s,:/etc/xdg,:$KOMETA_XDG_DIR:/etc/xdg,")"
;;
/etc/xdg )
tmp="$(echo "$tmp" | sed -e "s,^/etc/xdg,$KOMETA_XDG_DIR:/etc/xdg,")"
;;
esac
echo "$tmp"
}
_main(){
_check_runability "$1"
# $XDG_DATA_DIRS may be added
local result_xdg_config_dirs
result_xdg_config_dirs="$(_mk_xdg_config_dirs "$XDG_CONFIG_DIRS")"
case "$1" in
systemd )
echo XDG_CONFIG_DIRS="$result_xdg_config_dirs"
;;
profile )
export XDG_CONFIG_DIRS="$result_xdg_config_dirs"
;;
esac
}
if [ "$KOMETA_XDG_TESTING" = 0 ]; then
_main "$KOMETA_XDG_TYPE"
fi