1. Jack Frost
  2. misc

Commits

Jack Frost  committed b7455f1

smarter daemon

  • Participants
  • Parent commits 2262183
  • Branches master

Comments (0)

Files changed (1)

File chameleon

View file
 }
 
 chameleon.daemon() {
+	local last_image_file
+
 	[[ "$cfg_daemon_delay" ]] || { cfg_daemon_delay='900'; }
 
+	image_file=`chameleon.get_image`
+
 	while :; do
-		image_file=`chameleon.get_image`
-		chameleon.bg
-		sleep "$cfg_daemon_delay"
+		images=( `echo "${images[@]}" | sort -R` )
+		for i in "${images[@]}"; do
+			image_file="$i"
+			chameleon.bg
+			sleep "$cfg_daemon_delay"
+		done
 	done
 }
 
 
 # main
 
+chameleon.scan_dir() {
+	local file_type
+
+	[[ "$cfg_mode_recursive" ]] || { find_args+=( '-maxdepth 1' ); }
+	find_args+=( '-mindepth 1 -type f' )
+	find "$1" ${find_args[*]} | while read line; do
+		file_type=`file -ib "$line" | cut -d "/" -f 1`
+		[[ "$file_type" == "image" ]] && {
+			echo "$line"
+		}
+	done
+}
+
+chameleon.random_image() {
+	local random_number="$((RANDOM % ${#images[@]}))"
+	echo "${images[$random_number]}"
+}
+
 chameleon.get_image() {
 	[[ -d "$target" ]] && {
-		[[ "$cfg_mode_recursive" ]] || { find_args+=( '-maxdepth 1' ); }
-		find_args+=( '-mindepth 1 -type f' )
-		find "$target" ${find_args[*]} | sort -R | head -1 || { return 1; }
+		chameleon.random_image
 	} || {
 		echo "$target"
 	}
 	exit 7
 }
 
+[[ -d "$target" ]] && {
+	images=( `chameleon.scan_dir "$target"` )
+}
+
 [[ "$cfg_mode_daemon" ]] && {
 	chameleon.daemon; exit 0
 } || {