Skip to content

Commit 0c0369a

Browse files
author
kRHYME7
committed
feat: --filetypes arg to indicate filetypes for wallpaper.sh
ref #463 closes #463 This commit should enable users to have different preview depending on the backend.
1 parent b3bd595 commit 0c0369a

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

Configs/.local/lib/hyde/globalcontrol.sh

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,44 @@ get_hashmap() {
3535
unset wallHash
3636
unset wallList
3737
unset skipStrays
38-
unset verboseMap
38+
unset filetypes
39+
40+
list_extensions() {
41+
# Define supported file extensions
42+
supported_files=(
43+
"gif"
44+
"jpg"
45+
"jpeg"
46+
"png"
47+
"${WALLPAPER_FILETYPES[@]}"
48+
)
49+
if [ -n "${WALLPAPER_OVERRIDE_FILETYPES}" ]; then
50+
supported_files=("${WALLPAPER_OVERRIDE_FILETYPES[@]}")
51+
fi
52+
53+
printf -- "-iname \"*.%s\" -o " "${supported_files[@]}" | sed 's/ -o $//'
54+
55+
}
56+
57+
find_wallpapers() {
58+
local wallSource="$1"
59+
60+
if [ -z "${wallSource}" ]; then
61+
print_log -err "ERROR: wallSource is empty"
62+
return 1
63+
fi
64+
65+
local find_command
66+
find_command="find \"${wallSource}\" -type f \\( $(list_extensions) \\) -exec \"${hashMech}\" {} +"
67+
68+
[ "${LOG_LEVEL}" == "debug" ] && print_log -g "DEBUG:" -b "Running command:" "${find_command}"
69+
70+
tmpfile=$(mktemp)
71+
eval "${find_command}" 2>"$tmpfile" | sort -k2
72+
error_output=$(<"$tmpfile") && rm -f "$tmpfile"
73+
[ -n "${error_output}" ] && print_log -err "ERROR:" -b "found an error: " -r "${error_output}" -y " skipping..."
74+
75+
}
3976

4077
for wallSource in "$@"; do
4178

@@ -55,38 +92,6 @@ get_hashmap() {
5592

5693
[ "${LOG_LEVEL}" == "debug" ] && print_log -g "DEBUG:" -b "wallSource path:" "${wallSource}"
5794

58-
list_extensions() {
59-
# Define supported file extensions
60-
supported_files=(
61-
"gif"
62-
"jpg"
63-
"jpeg"
64-
"png"
65-
"${WALLPAPER_FILETYPES[@]}"
66-
)
67-
printf -- "-iname *.%s -o " "${supported_files[@]}" | sed 's/ -o $//'
68-
}
69-
70-
find_wallpapers() {
71-
local wallSource="$1"
72-
73-
if [ -z "${wallSource}" ]; then
74-
print_log -err "ERROR: wallSource is empty"
75-
return 1
76-
fi
77-
78-
local find_command
79-
find_command="find \"${wallSource}\" -type f \\( $(list_extensions) \\) ! -path \"*/logo/*\" -exec \"${hashMech}\" {} +"
80-
81-
[ "${LOG_LEVEL}" == "debug" ] && print_log -g "DEBUG:" -b "Running command:" "${find_command}"
82-
83-
tmpfile=$(mktemp)
84-
eval "${find_command}" 2>"$tmpfile" | sort -k2
85-
error_output=$(<"$tmpfile") && rm -f "$tmpfile"
86-
[ -n "${error_output}" ] && print_log -err "ERROR:" -b "found an error: " -r "${error_output}" -y " skipping..."
87-
88-
}
89-
9095
hashMap=$(find_wallpapers "${wallSource}") # Enable debug mode for testing
9196

9297
# hashMap=$(

Configs/.local/lib/hyde/wallpaper.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ options:
1919
-g, --get Get current wallpaper of specified backend
2020
-o, --output <file> Copy current wallpaper to specified file
2121
--link Resolved the linked wallpaper according to the theme
22+
-t --filetypes <types> Specify file types to override (comma-separated)
2223
-h, --help Display this help message
2324
2425
flags:
@@ -290,15 +291,18 @@ if [ -z "${*}" ]; then
290291
fi
291292

292293
# Define long options
293-
LONGOPTS="link,global,select,json,next,previous,random,set:,backend:,get,output:,help"
294+
LONGOPTS="link,global,select,json,next,previous,random,set:,backend:,get,output:,help,filetypes:"
294295

295296
# Parse options
296297
PARSED=$(
297-
if getopt --options GSjnprb:s:go:h --longoptions $LONGOPTS --name "$0" -- "$@"; then
298+
if getopt --options GSjnprb:s:t:go:h --longoptions $LONGOPTS --name "$0" -- "$@"; then
298299
exit 2
299300
fi
300301
)
301302

303+
# Initialize the array for filetypes
304+
WALLPAPER_OVERRIDE_FILETYPES=()
305+
302306
wallpaper_backend="${WALLPAPER_BACKEND:-swww}"
303307
wallpaper_setter_flag=""
304308
# Apply parsed options
@@ -354,6 +358,16 @@ while true; do
354358
wallpaper_output="${2}"
355359
shift 2
356360
;;
361+
-t | --filetypes)
362+
IFS=':' read -r -a WALLPAPER_OVERRIDE_FILETYPES <<<"$2"
363+
if [ "${LOG_LEVEL}" == "debug" ]; then
364+
for i in "${WALLPAPER_OVERRIDE_FILETYPES[@]}"; do
365+
print_log -g "DEBUG:" -b "filetype overrides : " "'${i}'"
366+
done
367+
fi
368+
export WALLPAPER_OVERRIDE_FILETYPES
369+
shift 2
370+
;;
357371
-h | --help)
358372
show_help
359373
;;

0 commit comments

Comments
 (0)