A collection of scripts

avoid using rm and small fixes

yemou 33d6bbe9 8a580e2a

Changed files
+7 -8
thm
+7 -8
thm
··· 10 10 hex2rgb() { 11 11 hex=$1 12 12 hex_r=${hex%????} 13 - hex_g=${hex#??} 14 - hex_g=${hex_g%??} 13 + hex_g=${hex#??}; hex_g=${hex_g%??} 15 14 hex_b=${hex#????} 16 15 printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b" 17 16 } ··· 21 20 && conf_dir="$THM_CONFIG_DIR" \ 22 21 || conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}/thm" 23 22 [ "$THM_DEST_DIR" ] \ 24 - && conf_dir="$THM_DEST_DIR" \ 23 + && dest_dir="$THM_DEST_DIR" \ 25 24 || dest_dir="${XDG_CACHE_HOME:-$HOME/.cache}/thm" 26 25 27 26 err() { ··· 59 58 color14_rgb="$(hex2rgb "$color14")" 60 59 color15_rgb="$(hex2rgb "$color15")" 61 60 62 - # Make sure the dest_dir exist 63 - [ -d "$dest_dir" ] || { mkdir -p "$dest_dir" || err "failed to create $dest_dir"; } 61 + # Make sure the dest_dir and dest_dir/thm_old exist 62 + [ -d "$dest_dir/thm_old" ] || { mkdir -p "$dest_dir/thm_old" || err "failed to create $dest_dir/thm_old"; } 64 63 65 - # Ensure the dest_dir is empty before populating it 66 - rm "$dest_dir/"* 64 + # Try and empty the dest_dir before populating it 65 + mv "$dest_dir/"* "$dest_dir/thm_old" 2> /dev/null 67 66 68 67 # Make a file with the name of the new theme 69 68 printf '%s\n' "$theme_file" > "$dest_dir/current_thm" ··· 115 114 done 116 115 117 116 # Run extra user scripts 118 - [ -d "$conf_dir/scripts" ] || return 0 117 + [ -d "$conf_dir/scripts" ] || exit 0 119 118 for i in "$conf_dir/scripts/"* 120 119 do 121 120 [ -x "$i" ] && $i > /dev/null 2>&1 &