File: geeqie-random-image

package info (click to toggle)
geeqie 1%3A2.5-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 16,780 kB
  • sloc: cpp: 110,189; xml: 11,497; sh: 3,681; awk: 124; perl: 88; python: 80; makefile: 23
file content (64 lines) | stat: -rwxr-xr-x 1,759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

## @file
## @brief Select and display a random image from a list of all images
## in Collections and the currently displayed folder
##

IFS='
'

# get list of images in all collections
collection_list=$(geeqie --remote --get-collection-list)

for collection_name in $collection_list
do
	collection_file_list=$(geeqie --remote --get-collection="$collection_name")
	for collection_file in $collection_file_list
		do
		list="${list:+${list}}\n${collection_file}"
		done
done

# get list of images in current folder
file_list=$(geeqie --remote --get-filelist=)

for file_name in $file_list
do
	class_whitespace="${file_name##*Class:}"
	class="${class_whitespace#"${class_whitespace%%[![:space:]]*}"}"

	if [ "$class" = "Image" ]
	then
		list="$list${file_name%%Class*}\n"
	fi

	if [ "$class" = "RAW Image" ]
	then
		list="$list""${file_name%%Class*}\n"
	fi
done

# remove blank lines
files_no_blanks=$(printf '%b\n' "$list" | sed -e 's/^[[:blank:]]*$//')

# remove leading trailing whitespace
files_no_spaces=$(printf '%b\n' "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//')

# remove duplicate lines and select random line
display_image=$( (printf '%b\n'  "$files_no_spaces")  | sort --uniq | shuf -n 1)

# get image currently displayed
current_image_collection=$(geeqie --remote --tell)
# remove collection name, if it is there
current_image_spaces="${current_image_collection%%Collection:*}"
# remove leading trailing whitespace
current_image=$(printf '%b\n' "$current_image_spaces" | sed 's/^[ \t]*//;s/[ \t]*$//')

# if the selected random image is currently displayed, try again
if [ "$current_image" = "$display_image" ]
then
	display_image=$(printf '%b' "$files_no_spaces" | sort --uniq | shuf -n 1)
fi

geeqie --remote file="$display_image"