A collection of scripts

avoid using rm and small fixes

yemou 33d6bbe9 8a580e2a

Changed files
+7 -8
thm
+7 -8
thm
···
hex2rgb() {
hex=$1
hex_r=${hex%????}
-
hex_g=${hex#??}
-
hex_g=${hex_g%??}
+
hex_g=${hex#??}; hex_g=${hex_g%??}
hex_b=${hex#????}
printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
}
···
&& conf_dir="$THM_CONFIG_DIR" \
|| conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}/thm"
[ "$THM_DEST_DIR" ] \
-
&& conf_dir="$THM_DEST_DIR" \
+
&& dest_dir="$THM_DEST_DIR" \
|| dest_dir="${XDG_CACHE_HOME:-$HOME/.cache}/thm"
err() {
···
color14_rgb="$(hex2rgb "$color14")"
color15_rgb="$(hex2rgb "$color15")"
-
# Make sure the dest_dir exist
-
[ -d "$dest_dir" ] || { mkdir -p "$dest_dir" || err "failed to create $dest_dir"; }
+
# Make sure the dest_dir and dest_dir/thm_old exist
+
[ -d "$dest_dir/thm_old" ] || { mkdir -p "$dest_dir/thm_old" || err "failed to create $dest_dir/thm_old"; }
-
# Ensure the dest_dir is empty before populating it
-
rm "$dest_dir/"*
+
# Try and empty the dest_dir before populating it
+
mv "$dest_dir/"* "$dest_dir/thm_old" 2> /dev/null
# Make a file with the name of the new theme
printf '%s\n' "$theme_file" > "$dest_dir/current_thm"
···
done
# Run extra user scripts
-
[ -d "$conf_dir/scripts" ] || return 0
+
[ -d "$conf_dir/scripts" ] || exit 0
for i in "$conf_dir/scripts/"*
do
[ -x "$i" ] && $i > /dev/null 2>&1 &