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="$(system_profiler SPBluetoothDataType | grep "Address:" | head -1 | sed "s/ *Address: \(.*\)/\1/g")"
[ "$BT_ADDRESS" = "" ] && \ [ "$BT_ADDRESS" = "" ] && \
__EXTRA="" || \ __EXTRA="" || \
__EXTRA=""" __EXTRA="export BT_DEVICE_ADDRESS=\"$BT_ADDRESS\""
export BT_DEVICE_ADDRESS=\"$BT_ADDRESS\""""
;; ;;
* ) * )
__EXTRA="" __EXTRA=""
;; ;;
esac esac
echo """#!/bin/zsh echo_config() {
$__EXTRA echo "#!/bin/zsh"
export ZDOTDIR=\"\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh\" [ "$__EXTRA" = "" ] || echo ""
[ -d \$ZDOTDIR ] || mkdir -p \$ZDOTDIR""" > /etc/__zshenv && \ echo "$__EXTRA"
mv -i /etc/__zshenv $ZSHENV_PATH 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 ln -si $ZSHENV_PATH /etc/zsh/zshenv