From 0f0497f9c5e995d6a03849e4ab36985179cd6468 Mon Sep 17 00:00:00 2001 From: Andreas Schuster Date: Sat, 19 Apr 2025 19:10:25 +0200 Subject: [PATCH] zephyr-env.sh: Use $XDG_CONFIG_HOME/zephry/zephyrrc if present According to the [XDG Base Directory Specification] there is a single base directory in which user configuration files should be stored. This helps users to keep their home directory uncluttered. This base directory can be set in the environment variable $XDG_CONFIG_HOME and defaults to ${HOME}/.config if $XDG_CONFIG_HOME is not set. This commit adjusts the zephyr-env.sh script to look for a user configuration file in the following locations: - $XDG_CONFIG_HOME/zephyr/zephyrrc - $HOME/.config/zephyr/zephyrrc - $HOME/.zephyrrc The first one that is found will be used. [XDG Base Directory Specification]: (https://specifications.freedesktop.org/basedir-spec/latest/) Signed-off-by: Andreas Schuster --- zephyr-env.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zephyr-env.sh b/zephyr-env.sh index d5036712a25..3be8ef52720 100644 --- a/zephyr-env.sh +++ b/zephyr-env.sh @@ -64,6 +64,14 @@ zephyr_answer_file=~/zephyr-env_install.bash . ${zephyr_answer_file} } unset zephyr_answer_file -zephyr_answer_file=~/.zephyrrc -[ -f ${zephyr_answer_file} ] && . ${zephyr_answer_file} -unset zephyr_answer_file +xdg_config_home="${XDG_CONFIG_HOME:-${HOME}/.config}" +zephyr_xdg_rc="${xdg_config_home}/zephyr/zephyrrc" +if [ -f "${zephyr_xdg_rc}" ]; then + . "${zephyr_xdg_rc}" +else + zephyr_answer_file=~/.zephyrrc + [ -f "${zephyr_answer_file}" ] && . "${zephyr_answer_file}" + unset zephyr_answer_file +fi +unset zephyr_xdg_rc +unset xdg_config_home