refactor(script/zsh-xdg-setup): Print the config before writing the file

Also make it more posix-compliant just in case
This commit is contained in:
Ahmad Ansori Palembani 2024-07-20 09:19:59 +07:00
parent 2139e16219
commit 0d5e65b823
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -16,17 +16,24 @@ case "$OSTYPE" in
BT_ADDRESS="$(system_profiler SPBluetoothDataType | grep "Address:" | head -1 | sed "s/ *Address: \(.*\)/\1/g")"
[ "$BT_ADDRESS" = "" ] && \
__EXTRA="" || \
__EXTRA="""
export BT_DEVICE_ADDRESS=\"$BT_ADDRESS\""""
__EXTRA="export BT_DEVICE_ADDRESS=\"$BT_ADDRESS\""
;;
* )
__EXTRA=""
;;
esac
echo """#!/bin/zsh
$__EXTRA
export ZDOTDIR=\"\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh\"
[ -d \$ZDOTDIR ] || mkdir -p \$ZDOTDIR""" > /etc/__zshenv && \
mv -i /etc/__zshenv $ZSHENV_PATH
echo_config() {
echo "#!/bin/zsh"
[ "$__EXTRA" = "" ] || echo ""
echo "$__EXTRA"
echo "export ZDOTDIR=\"\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh\""
echo "[ -d \$ZDOTDIR ] || mkdir -p \$ZDOTDIR"
}
echo_config > /tmp/__zshenv || exit 1
echo "========/etc/zshenv========="
cat /tmp/__zshenv
echo "============================"
mv -i /tmp/__zshenv $ZSHENV_PATH
ln -si $ZSHENV_PATH /etc/zsh/zshenv