Repository navigation
Expand file tree
/
Copy pathupdate-dots.dev.sh
More file actions
executable file
·134 lines (113 loc) · 3.75 KB
/
Copy pathupdate-dots.dev.sh
File metadata and controls
executable file
·134 lines (113 loc) · 3.75 KB
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
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
export base="$(pwd)"
start_time=$(date +%s%N)
source ./scriptdata/environment-variables
GREEN="\033[0;32m"
RED="\033[0;31m"
BLUE="\033[0;34m"
CYAN="\033[0;36m"
YELLOW="\033[1;33m"
RESET="\033[0m"
config_folders=(".config")
excludes=(".config/hypr/custom" ".config/ags/user_options.js" ".config/hypr/hyprland.conf")
get_destination() {
local file="$1"
if [ "$(echo $file | cut -d/ -f1)" = ".config" ]; then
printf "$XDG_CONFIG_HOME/$(echo $file | cut -d/ -f2-)"
elif [ "$(echo $file | cut -d/ -f1-2)" = ".local/bin" ]; then
printf "$XDG_BIN_HOME/$(echo $file | cut -d/ -f3-)"
fi
}
file_in_excludes() {
local file="$1"
for exc in "${excludes[@]}"; do
if [[ $file == "$exc"* ]]; then
return 0
fi
done
return 1
}
echo -e "${CYAN}Starting configuration update...${RESET}"
echo -e "${YELLOW}The following files and folders will be preserved:${RESET} ${excludes[@]}"
# Backup excluded files
temp_dir="/tmp/dots_backup"
for exc in "${excludes[@]}"; do
if [ -e "$(get_destination "$exc")" ]; then
echo -e "${BLUE}Saving ${exc}...${RESET}"
mkdir -p "$temp_dir/$(dirname "$exc")"
cp -r "$(get_destination "$exc")" "$temp_dir/$(dirname "$exc")/"
fi
done
echo -e "${CYAN}Removing old configs...${RESET}"
for dir in "$base/.config"/*; do
if [ -d "$dir" ]; then
config_name=$(basename "$dir")
target_dir="$XDG_CONFIG_HOME/$config_name"
if [ -d "$target_dir" ]; then
echo -e "${RED}Removing $target_dir${RESET}"
rm -rf "$target_dir"
fi
fi
done
if [ -d "$temp_dir" ]; then
echo -e "${BLUE}Restoring saved files...${RESET}"
for exc in "${excludes[@]}"; do
if [ -e "$temp_dir/$exc" ]; then
mkdir -p "$(dirname "$(get_destination "$exc")")"
cp -r "$temp_dir/$exc" "$(get_destination "$exc")"
fi
done
rm -rf "$temp_dir"
fi
echo -e "${CYAN}Copying new files...${RESET}"
mkdir -p "$HOME/.ags"
cp -f "$base/.config/ags/modules/.configuration/user_options.default.json" "$HOME/.ags/config.json"
mkdir -p "$XDG_BIN_HOME"
if [ -d "$base/.local/bin" ]; then
cp -f "$base/.local/bin/"* "$XDG_BIN_HOME/"
chmod +x "$XDG_BIN_HOME"/*
fi
for folder in "${config_folders[@]}"; do
find "$folder" -type f -print0 | while IFS= read -r -d '' file; do
if ! file_in_excludes "$file"; then
destination="$(get_destination "$file")"
echo -e "${BLUE}Copying \"$file\" to \"$destination\" ...${RESET}"
mkdir -p "$(dirname "$destination")"
cp -f "$base/$file" "$destination"
else
echo -e "${YELLOW}Skipping $file${RESET}"
fi
done
done
wait
clear
nohup hyprctl reload >/dev/null 2>&1 &
echo -e "${GREEN}Hyprland reloaded${RESET}"
echo -e "${CYAN}Restarting AGS...${RESET}"
ags -q >/dev/null 2>&1
temp_log="/tmp/ags_restart.log"
touch "$temp_log"
ags > "$temp_log" 2>&1 &
timeout=10
while [ $timeout -gt 0 ]; do
if ags_load_time=$(grep "AGS loaded in" "$temp_log" | tail -n 1 | sed 's/.*AGS loaded in \([0-9.]*\)s/\1/'); then
if [ ! -z "$ags_load_time" ]; then
break
fi
fi
sleep 0.5
timeout=$((timeout - 1))
done
if [ $timeout -gt 0 ]; then
echo -e "${GREEN}AGS restarted in ${CYAN}${ags_load_time}${GREEN} seconds${RESET}"
else
echo -e "${RED}Timeout waiting for AGS to load${RESET}"
fi
rm -f "$temp_log"
end_time=$(date +%s%N)
execution_time=$(LC_NUMERIC=C printf "%.3f" $(echo "($end_time - $start_time) / 1000000000" | bc -l))
echo -e "\n${CYAN}✨ Configuration update completed:${RESET}"
echo -e "${GREEN}├─${RESET} Total time: ${CYAN}${execution_time}s${RESET}"
echo -e "${GREEN}└─${RESET} Status: ${GREEN}Done${RESET}\n"