-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortImages
More file actions
executable file
·56 lines (48 loc) · 1.3 KB
/
sortImages
File metadata and controls
executable file
·56 lines (48 loc) · 1.3 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
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
# Check if it is a directory, file or invalid
isDir() {
if [[ -d $1 ]]; then
# This is a directory
return 1
elif [[ -f $1 ]]; then
# This is a file
return 2
else
# This is invalid
return 0
fi
}
# Handles logic according to the file type
handleType() {
# If it is a directory, then go through the directory to check for files
# or directories
if [[ $1 -eq 1 ]]; then
echo -e "\n${BLUE}"Sorting through "$2"..."${RED}\n"
ImageInfoFEH=("$(feh -L "%f|R:%wx%h|%p|%t" -S pixels -r "$2")")
echo "${ImageInfoFEH[0]}" >>imageInfo.txt
echo -e "\n${BLUE}"Sorting finished. Results in imageInfo.txt"${NC}"
# If it is a file, check if it is an image
elif [[ $1 -eq 2 ]]; then
IsIt=$(file "$2" --mime-type -b)
NeedImageOnly="ItIs_"${IsIt/'/'*/}
# If it is an image, print its information
if [ "$NeedImageOnly" == "ItIs_image" ]; then
echo -e "\n${BLUE}"Sorting through "$2"..."${RED}\n"
ImageInfoFEH=("$(feh -L "%f|R:%wx%h|%p|%t" "$2")")
echo "${ImageInfoFEH[0]}" >>imageInfo.txt
echo -e "\n${BLUE}"Sorting finished. Results in imageInfo.txt"${NC}"
fi
fi
}
if [[ $1 == '' ]]; then
PAR=$(pwd)
else
PAR=$1
fi
isDir "$PAR"
TYPE=$?
handleType "$TYPE" "$PAR"