-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobs
More file actions
executable file
·92 lines (84 loc) · 2.2 KB
/
globs
File metadata and controls
executable file
·92 lines (84 loc) · 2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env zsh
usage() {
echo "Usage: $(basename "$0") <images|videos|media> [-x ext ...]" >&2
echo >&2
echo "Prints glob patterns one per line for use in scripts." >&2
echo >&2
echo " images — raster images, raw formats, and modern compressed formats" >&2
echo " raw — camera raw formats (arw, cr2, dng, nef, etc.)" >&2
echo " videos — common video container formats" >&2
echo " media — both images and videos" >&2
echo >&2
echo "Options:" >&2
echo " -x, --exclude ext [ext ...] exclude one or more extensions (without leading dot)" >&2
echo >&2
echo "Examples:" >&2
echo " $(basename "$0") images -x heic heif" >&2
echo " $(basename "$0") images -x jpg jpeg" >&2
echo " $(basename "$0") videos -x wmv flv" >&2
exit 1
}
print_raw() {
print -l \
"*.arw" "*.cr2" "*.cr3" "*.dng" "*.nef" \
"*.orf" "*.raf" "*.raw" "*.rw2" "*.pef" "*.srw" "*.x3f"
}
print_images() {
print -l \
"*.jpg" "*.jpeg" \
"*.png" "*.gif" "*.bmp" \
"*.tiff" "*.tif" "*.tga" \
"*.webp" "*.avif" \
"*.heic" "*.heif" \
"*.jxl" \
"*.psd"
print_raw
}
print_videos() {
print -l \
"*.mp4" "*.m4v" \
"*.mov" \
"*.mkv" \
"*.avi" \
"*.webm" \
"*.ts" "*.mts" "*.m2ts" \
"*.wmv" "*.flv"
}
# Parse type
case "${1:-}" in
images|img|i) type=images ;;
raw|r) type=raw ;;
videos|video|vid|v) type=videos ;;
media|all) type=media ;;
*) usage ;;
esac
shift
# Parse -x / --exclude
excludes=()
while [[ $# -gt 0 ]]; do
case "$1" in
-x|--exclude)
shift
while [[ $# -gt 0 && "$1" != -* ]]; do
excludes+=("$1")
shift
done
;;
*) usage ;;
esac
done
emit() {
case "$type" in
images) print_images ;;
raw) print_raw ;;
videos) print_videos ;;
media) print_images; print_videos ;;
esac
}
if [[ ${#excludes[@]} -gt 0 ]]; then
pattern=$(printf "%s|" "${excludes[@]}")
pattern="\.(${pattern%|})$"
emit | grep -vEi "$pattern"
else
emit
fi