4 ## @brief Select and display a random image from a list of all images
5 ## in Collections and the currently displayed folder
11 # get list of images in all collections
12 collection_list=$(geeqie --remote --get-collection-list)
14 for collection_name in $collection_list
16 collection_file_list=$(geeqie --remote --get-collection="$collection_name")
17 for collection_file in $collection_file_list
19 list="${list:+${list}}\n${collection_file}"
23 # get list of images in current folder
24 file_list=$(geeqie --remote --get-filelist=)
26 for file_name in $file_list
28 class_whitespace="${file_name##*Class:}"
29 class="${class_whitespace#"${class_whitespace%%[![:space:]]*}"}"
31 if [ "$class" = "Image" ]
33 list="$list${file_name%%Class*}\n"
36 if [ "$class" = "RAW Image" ]
38 list="$list""${file_name%%Class*}\n"
43 files_no_blanks=$(printf '%b\n' "$list" | sed -e 's/^[[:blank:]]*$//')
45 # remove leading trailing whitespace
46 files_no_spaces=$(printf '%b\n' "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//')
48 # remove duplicate lines and select random line
49 display_image=$( (printf '%b\n' "$files_no_spaces") | sort --uniq | shuf -n 1)
51 # get image currently displayed
52 current_image_collection=$(geeqie --remote --tell)
53 # remove collection name, if it is there
54 current_image_spaces="${current_image_collection%%Collection:*}"
55 # remove leading trailing whitespace
56 current_image=$(printf '%b\n' "$current_image_spaces" | sed 's/^[ \t]*//;s/[ \t]*$//')
58 # if the selected random image is currently displayed, try again
59 if [ "$current_image" = "$display_image" ]
61 display_image=$(printf '%b' "$files_no_spaces" | sort --uniq | shuf -n 1)
64 geeqie --remote file="$display_image"