diff options
-rw-r--r-- | src/lib/conf.sh | 6 | ||||
-rw-r--r-- | test/lib-conf-test.sh | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/conf.sh b/src/lib/conf.sh index b9e8698..845f4c1 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -18,7 +18,11 @@ INCLUDE_CONF_SH=conf.sh LIBREUSER="${SUDO_USER:-$USER}" -LIBREHOME="$(eval echo ~$LIBREUSER)" +if [[ $LIBREUSER == $USER ]]; then + LIBREHOME=$HOME +else + LIBREHOME="$(eval echo ~$LIBREUSER)" +fi if [[ -z ${XDG_CONFIG_HOME:-} ]]; then export XDG_CONFIG_HOME="${LIBREHOME}/.config" fi diff --git a/test/lib-conf-test.sh b/test/lib-conf-test.sh index bb6b285..eeea287 100644 --- a/test/lib-conf-test.sh +++ b/test/lib-conf-test.sh @@ -20,3 +20,21 @@ it_sets_makepkg_vars_in_custom_file() { . "$tmpdir/makepkg.conf" [[ $PKGDEST == /pkgdest ]] } + +it_figures_out_HOME_when_root() { + cd "$tmpdir" + echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh + + LIBREHOME=$(sudo bash ./test.sh) + [[ $LIBREHOME == $HOME ]] +} + +it_respects_custom_HOME() { + cd "$tmpdir" + echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh + + export HOME=/foo + LIBREHOME=$(bash ./test.sh) + + [[ $LIBREHOME == /foo ]] +} |