Eliminate some GitHub action warnings
[geeqie.git] / plugins / random-image / geeqie-random-image
1 #!/bin/sh
2
3 ## @file
4 ## @brief Select and display a random image from a list of all images
5 ## in Collections and the currently displayed folder
6 ##
7
8 IFS='
9 '
10
11 # get list of images in all collections
12 collection_list=$(geeqie --remote --get-collection-list)
13
14 for collection_name in $collection_list
15 do
16         collection_file_list=$(geeqie --remote --get-collection="$collection_name")
17         for collection_file in $collection_file_list
18                 do
19                 list="${list:+${list}}\n${collection_file}"
20                 done
21 done
22
23 # get list of images in current folder
24 file_list=$(geeqie --remote --get-filelist=)
25
26 for file_name in $file_list
27 do
28         class_whitespace="${file_name##*Class:}"
29         class="${class_whitespace#"${class_whitespace%%[![:space:]]*}"}"
30
31         if [ "$class" = "Image" ]
32         then
33                 list="$list${file_name%%Class*}\n"
34         fi
35
36         if [ "$class" = "RAW Image" ]
37         then
38                 list="$list""${file_name%%Class*}\n"
39         fi
40 done
41
42 # remove blank lines
43 files_no_blanks=$(printf '%b\n' "$list" | sed -e 's/^[[:blank:]]*$//')
44
45 # remove leading trailing whitespace
46 files_no_spaces=$(printf '%b\n' "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//')
47
48 # remove duplicate lines and select random line
49 display_image=$( (printf '%b\n'  "$files_no_spaces")  | sort --uniq | shuf -n 1)
50
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]*$//')
57
58 # if the selected random image is currently displayed, try again
59 if [ "$current_image" = "$display_image" ]
60 then
61         display_image=$(printf '%b' "$files_no_spaces" | sort --uniq | shuf -n 1)
62 fi
63
64 geeqie --remote file="$display_image"