-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_dotfiles.sh
executable file
·89 lines (73 loc) · 2.14 KB
/
update_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
echo_success() {
echo -e "\e[32;1m[$1]\e[0m\e[32m $2\e[0m"
}
echo_warning() {
echo -e "\e[33;1m[$1]\e[0m\e[33m $2\e[0m"
}
echo_error() {
echo -e "\e[31;1m[$1]\e[0m\e[31m $2\e[0m"
}
link_thing() {
local thing_name="$1"
local source_path="$CHACHI_PATH/home/$thing_name"
local target_path="$HOME/$thing_name"
local backup_path="${target_path}.bak"
if [ -f "$source_path" ] && [ -d "$target_path" ]; then
echo_error "$thing_name" "'$target_path' is a directory, it should be a file"
return 1
fi
if [ -d "$source_path" ] && [ -f "$target_path" ]; then
echo_error "$thing_name" "'$target_path' is a file, it should be a directory"
return 1
fi
if [ -L "$target_path" ]; then
local existing_link="$(readlink $target_path)"
if [ "$source_path" = "$existing_link" ]; then
echo_success "$thing_name" "already linked"
return 0
else
echo_error "[$thing_name]" "'$target_path' is already a link to '$existing_link'"
return 2
fi
fi
if [ -e "$target_path" ]; then
echo_warning "$thing_name" "'$target_path' already exists, moving to '$backup_path'"
if [ -e "$backup_path" ]; then
echo_error "$thing_name" "'$backup_path' backup directory already exists"
return 3
fi
mv "$target_path" "$backup_path"
fi
ln -s "$source_path" "$target_path"
echo_success "$thing_name" "'$target_path' → '$source_path'"
}
if [ -z "$CHACHI_PATH" ]; then
echo_error "dotfiles" "CHACHI_PATH is not set. Add this to your environment before running this script."
exit 1
fi
link_thing .bin
link_thing .ssh
link_thing .config/alacritty
link_thing .config/environment.d
link_thing .config/fish
link_thing .config/git
link_thing .config/hypr
link_thing .config/i3
link_thing .config/karabiner
link_thing .config/lazygit
link_thing .config/nushell
link_thing .config/nvim
link_thing .config/rofi
link_thing .config/starship
link_thing .config/sway
link_thing .config/systemd
link_thing .config/tmux
link_thing .config/waybar
link_thing .Xdefaults
link_thing .Xresources
link_thing .bash_profile
link_thing .bashrc
link_thing .editorconfig
link_thing .gitconfig
link_thing .ideavimrc