From 0d5e65b82358e768da29c2ef2520a80540130e95 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Sat, 20 Jul 2024 09:19:59 +0700 Subject: [PATCH] refactor(script/zsh-xdg-setup): Print the config before writing the file Also make it more posix-compliant just in case --- zsh-xdg-setup | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/zsh-xdg-setup b/zsh-xdg-setup index 3bae512..8af13e2 100755 --- a/zsh-xdg-setup +++ b/zsh-xdg-setup @@ -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