-
Notifications
You must be signed in to change notification settings - Fork 1
/
link-dotfiles.zsh
executable file
·36 lines (33 loc) · 1.46 KB
/
link-dotfiles.zsh
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
#!/bin/zsh
# Script execution check
test -n "$PS1" \
&& echo -e "This script \033[00;31mshould be executed\033[0m not sourced!" && return
# == File linking =========================================
# Most selected files can be sourced but these here are
# used by external tools and need to be sym-linked
# p10k file linking
if ! [ "$(realpath "$HOME/.p10k.zsh")" = "$DOTFILES_REPO/p10k/$DOTFILES_P10K" ]; then
# remove if it is a link
test -L "$HOME/.p10k.zsh" \
&& rm "$HOME/.p10k.zsh"
# move to old if it is a file
test -f "$HOME/.p10k.zsh" \
&& mv "$HOME/.p10k.zsh" "$HOME/.p10k.zsh.old"
# Link if possible or throw an error
test -f "$DOTFILES_REPO/p10k/$DOTFILES_P10K" \
&& ln -s "$DOTFILES_REPO/p10k/$DOTFILES_P10K" "$HOME/.p10k.zsh" \
|| echo "Error: \"$DOTFILES_REPO/p10k/$DOTFILES_P10K\" does not exist for linking \n to \$HOME/.p10k.zsh"
fi
# vimrc file linking
if ! [ "$(realpath "$HOME/.vimrc")" = "$DOTFILES_REPO/vimrc/$DOTFILES_VIMRC" ]; then
# remove if it is a link
test -L "$HOME/.vimrc" \
&& rm "$HOME/.vimrc"
# move to old if it is a file
test -f "$HOME/.vimrc" \
&& mv "$HOME/.vimrc" "$HOME/.vimrc.old"
# Link if possible or throw an error
test -f "$DOTFILES_REPO/vimrc/$DOTFILES_VIMRC" \
&& ln -s "$DOTFILES_REPO/vimrc/$DOTFILES_VIMRC" "$HOME/.p10k.zsh" \
|| echo "Error: \"$DOTFILES_REPO/vimrc/$DOTFILES_VIMRC\" does not exist for linking \n to \$HOME/.p10k.zsh"
fi