forked from void-land/hyprland-void-dots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstow.sh
executable file
·145 lines (115 loc) · 3.09 KB
/
stow.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
LINUX_CONFIGS_DIR="$(pwd)/linux-configs"
LINUX_DOTFILES_DIR="$LINUX_CONFIGS_DIR/dotfiles"
NIX_DIR="$LINUX_CONFIGS_DIR/nix"
ZSH_DIR="$LINUX_CONFIGS_DIR/shells/zsh"
FISH_DIR="$LINUX_CONFIGS_DIR/shells/fish"
UTILS_DIR="$LINUX_CONFIGS_DIR/utils"
ZED_DIR="$LINUX_CONFIGS_DIR/editors/zed"
VIM_DIR="$LINUX_CONFIGS_DIR/editors/vim"
NVIM_DIR="$LINUX_CONFIGS_DIR/editors/nvim"
HYPRLAND_ROOT="$(pwd)/hypr-configs"
HYPRLAND_DIR="$HYPRLAND_ROOT/dotfiles"
SHORTCUTS_DIR="$HYPRLAND_ROOT/shortcuts"
display_help() {
echo "Usage: [-s | -u] [-h]"
echo " -s Stow dotfiles"
echo " -u Unstow dotfiles"
echo " -h Display this help message"
}
log() {
local timestamp=$(date +"%T")
local message="======> $1 : $timestamp"
echo -e "\n$message\n"
}
create_link() {
local source=$1
local target=$2
if [ ! -e "$source" ]; then
echo "Source does not exist: $source"
return 1
fi
if [ ! -d "$(dirname "$target")" ]; then
mkdir -p "$(dirname "$target")"
fi
if [ -e "$target" ]; then
rm -rf "$target"
fi
ln -sfn "$source" "$target"
echo "$source ===> $target"
}
create_links() {
local source_dir=$1
local target_dir=$2
if [ ! -d $source_dir ]; then
echo "Source directory does not exist."
return 1
fi
if [ ! -d $target_dir ]; then
mkdir -p $target_dir
fi
for item in "$source_dir"/* "$source_dir"/.*; do
if [ -e "$item" ] && [ "$item" != "$source_dir/." ] && [ "$item" != "$source_dir/.." ]; then
echo "$item ===> $target_dir"
ln -sfn "$item" "$target_dir/"
fi
done
}
delete_links() {
local source_dir=$1
local target_dir=$2
if [ ! -d $source_dir ] || [ ! -d $target_dir ]; then
echo "Source or target directory does not exist."
return 1
fi
for config in "$source_dir"/* "$source_dir"/.*; do
config_name=$(basename $config)
target_config="$target_dir/$config_name"
if [ -e "$target_config" ]; then
rm -rf $target_config
echo "Removed: $target_config"
else
echo "Not found: $target_config"
fi
done
}
create_target_dir() {
mkdir -p ~/.local/share/applications
mkdir -p ~/.config
}
stow() {
create_target_dir
create_link $FISH_DIR ~/.config/fish
log "Fish dotfiles stowed successfully!"
create_links $LINUX_DOTFILES_DIR ~/.config
log "Base dotfiles stowed successfully!"
create_links $HYPRLAND_DIR ~/.config
log "Hyprland dotfiles stowed successfully!"
create_links $UTILS_DIR ~
log "Utilities stowed successfully!"
}
unstow() {
delete_links $LINUX_DOTFILES_DIR ~/.config
delete_links $HYPRLAND_DIR ~/.config
delete_links $SHORTCUTS_DIR ~/.local/share/applications
delete_links $UTILS_DIR ~
log "All configs ustowed successfully !"
}
while getopts "ush" opt; do
case $opt in
s)
clear
stow
;;
u)
unstow
;;
h)
display_help
exit 0
;;
esac
done
if [[ $# -eq 0 ]]; then
display_help
fi