-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-dotfiles.sh
executable file
·39 lines (34 loc) · 1.05 KB
/
link-dotfiles.sh
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/zsh
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) MACHINE=Linux;;
Darwin*) MACHINE=Mac;;
CYGWIN*) MACHINE=Cygwin;;
MINGW*) MACHINE=MinGw;;
*) MACHINE="UNKNOWN:${unameOut}"
esac
echo "Creating symlinks for dotfiles to $HOME"
# Symlink all dotfiles on Mac
if [[ $MACHINE == "Mac" ]]; then
for f in dotfiles/\.[^.]*; do
FILE="$(basename $f)"
ln -sf "$PWD/dotfiles/$FILE" "$HOME"
done
fi
# .zshrc cannot be symlinked on WSL. ZSH will break if symlinked. Copy instead.
# This might change in WSL2
if [[ $MACHINE == "Linux" ]]; then
for f in dotfiles/\.[^.]*; do
FILE="$(basename $f)"
if [[ $FILE == ".zshrc" ]]; then
echo ".zshrc cannot be symlinked. Copying instead."
cp -p "$PWD/dotfiles/.zshrc" "$HOME"
else
ln -sf "$PWD/dotfiles/$FILE" "$HOME"
fi
done
fi
# Source .zshrc to update env
# Ignore the errors generated by this source.
# They only appear during this process. They work properly on new shell startup.
echo "Linked dotfiles. Please restart your shell. "