dotfiles/zsh-xdg-setup
Ahmad Ansori Palembani ea122dc39a
fix(zsh): Make $ZDOTDIR if it doesn't exists
Try to prevent "No such file or directory" error
2024-07-11 13:16:42 +07:00

26 lines
793 B
Bash
Executable file

#!/bin/bash
[ "${EUID:-$(id -u)}" -eq 0 ] || { >&2 echo "Please run this as root."; exit 1; }
ZSHENV_PATH="/etc/zshenv"
case "$(realpath $ZSHENV_PATH)" in
*"/nix/"* )
ZSHENV_PATH="/etc/zshenv.local"
;;
esac
__EXTRA=""
if [[ "$OSTYPE" == "darwin"* ]]; then
# REF: https://github.com/null2264/Hackintosh-L460?tab=readme-ov-file#bluetooth-workaround
BT_ADDRESS="$(system_profiler SPBluetoothDataType | grep "Address:" | head -1 | sed "s/ *Address: \(.*\)/\1/g")"
[ "$BT_ADDRESS" = "" ] || __EXTRA="""
export BT_DEVICE_ADDRESS=\"$BT_ADDRESS\""""
fi
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
ln -si $ZSHENV_PATH /etc/zsh/zshenv