-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh-xdg-setup
executable file
·39 lines (33 loc) · 1.07 KB
/
zsh-xdg-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
[ "${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
case "$OSTYPE" in
"darwin"* ) # We can't access ZI_IS_DARWIN just yet, so we'll do it manually
# REF: https://github.com/null2264/ThinkPad-L460-OpenCore/blob/d7b92805f14947c14359b53bd8ff6af199883c36/README.md#bluetooth-workaround
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=""
;;
esac
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