diff --git a/thm b/thm index 7afc724..fc7e70c 100755 --- a/thm +++ b/thm @@ -10,8 +10,7 @@ usage() { 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" } @@ -21,7 +20,7 @@ hex2rgb() { && 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() { @@ -59,11 +58,11 @@ color13_rgb="$(hex2rgb "$color13")" 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" @@ -115,7 +114,7 @@ do 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 &