many improvements
This commit is contained in:
parent
b6f7ffccba
commit
4811e675d8
|
@ -1,14 +1,44 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
shared_themes_dir=/usr/share/themes/
|
|
||||||
home_local_themes_dir="$HOME/.local/share/themes/"
|
# Exit out if the same script is already running in the background
|
||||||
source_theme_dirs=("$shared_themes_dir" "$home_local_themes_dir")
|
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
||||||
|
|
||||||
|
# Set the directory paths
|
||||||
|
|
||||||
target_themes_dir="$HOME/.themes"
|
target_themes_dir="$HOME/.themes"
|
||||||
|
target_icons_dir="$HOME/.icons"
|
||||||
|
|
||||||
mkdir -p "$target_themes_dir" "$home_local_themes_dir" ||
|
# Create target directories if they don't exist
|
||||||
{ echo "failed to make directoris $target_themes_dir & $home_local_themes_dir"; exit 1; }
|
mkdir -p "$target_themes_dir" "$target_icons_dir" ||
|
||||||
|
{ echo "failed to make directories $target_themes_dir & $target_icons_dir"; exit 1; }
|
||||||
|
|
||||||
echo "Set watch for" "${source_theme_dirs[@]}" "directories ..."
|
# Go through each item in $XDG_DATA_DIRS to find all other directories where
|
||||||
inotifywait -qmr -e 'modify,attrib,move,move_self,create,delete,delete_self,unmount' "${source_theme_dirs[@]}" | while read -r events; do
|
# themes & icons are stored, and save these to source_themes_dirs & source_icons_dirs respectively
|
||||||
rsync -av --delete --progress "${source_theme_dirs[@]}" "$target_themes_dir"
|
while read -r dir; do
|
||||||
echo "Directory $target_themes_dir is synchronized with" "${source_theme_dirs[@]}"
|
themes_subdir=${dir%/}/themes
|
||||||
|
icons_subdir=${dir%/}/icons
|
||||||
|
# Directories inside user's home directory will be created if nonexistant
|
||||||
|
for subdir in $themes_subdir $icons_subdir; do
|
||||||
|
[[ "$subdir" = "$HOME"/* ]] && mkdir -p "$subdir"
|
||||||
|
done
|
||||||
|
[ -d "$themes_subdir" ] && source_themes_dirs+=("$themes_subdir/")
|
||||||
|
[ -d "$icons_subdir" ] && source_icons_dirs+=("$icons_subdir/")
|
||||||
|
done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
|
||||||
|
|
||||||
|
# Function to synchronize themes and icons from source to target directory
|
||||||
|
sync_themes_and_icons() {
|
||||||
|
rsync -av --delete --progress "${source_themes_dirs[@]}" "$target_themes_dir"
|
||||||
|
rsync -av --delete --progress "${source_icons_dirs[@]}" "$target_icons_dir"
|
||||||
|
echo "Directories $target_themes_dir and $target_icons_dir are synchronized with source directories"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initial synchronization
|
||||||
|
sync_themes_and_icons
|
||||||
|
|
||||||
|
echo "Set watch for theme directories:" "${source_themes_dirs[@]}" ", and icon directories:" "${source_icons_dirs[@]}"
|
||||||
|
|
||||||
|
# Start watching for file changes in the source theme and icon directories
|
||||||
|
inotifywait -qmr -e 'modify,attrib,move,move_self,create,delete,delete_self,unmount' "${source_themes_dirs[@]}" "${source_icons_dirs[@]}" |
|
||||||
|
while read -r _; do
|
||||||
|
sync_themes_and_icons
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user