-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-fuzzy
executable file
·61 lines (56 loc) · 1.87 KB
/
find-fuzzy
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
#!/bin/bash
# See <https://www.fosslinux.com/46761/recursively-find-list-the-files-by-dat-linux.htm>
# find "`pwd`" -type f -printf '%T@ %t %p\n' | sort -k 1 -n | cut -d ' ' -f2-
# ^ type f: only files
# ^ type d: only directories
usage(){
>&2 cat <<END
find-fuzzy <criteria> [option]
The criteria you specify is used as a case-insensitive substring for finding files.
The current working directory (cwd) is used unless --thing is specified.
Options:
--thing Search only in ~/Meshes and either ~/Nextcloud/Meshes or
~/ownCloud/Meshes, whichever exists (Nextcloud has priority).
Examples:
find-fuzzy oblin # Find files like Goblins.stl and GOBLIN.stl in cwd.
fund-fuzzy GOBL --thing # Find the same files but only in "Meshes" directories listed above.
END
}
fuzz="$1"
option=""
if [ "x$1" == "x--thing" ]; then
fuzz="$2"
option="--thing"
fi
if [ "x" = "x$fuzz" ]; then
>&2 printf "[find-fuzzy] Error: You didn't specify a criteria for the"
if [ "x$option" != "x" ]; then
>&2 printf " $option"
fi
echo " search."
exit 1
fi
if [ "x$option" == "x--thing" ]; then
has_any=false
if [ -d "$HOME/Meshes" ]; then
find "$HOME/Meshes" -iname "*$fuzz*"
has_any=true
else
>&2 echo "[find-fuzzy] Warning: There is no $HOME/Meshes for the '--thing' option."
fi
if [ -d "$HOME/Nextcloud/Meshes" ]; then
find "$HOME/Nextcloud/Meshes" -iname "*$fuzz*"
has_any=true
elif [ -d "$HOME/ownCloud/Meshes" ]; then
find "$HOME/ownCloud/Meshes" -iname "*$fuzz*"
has_any=true
else
>&2 echo "[find-fuzzy] Warning: There is no $HOME/Nextcloud/Meshes nor $HOME/ownCloud/Meshes for the '--thing' option."
fi
if [ "$has_any" != "true" ]; then
>&2 echo "[find-fuzzy] Error: There are 0 known '--thing' locations."
exit 1
fi
else
find "`pwd`" -iname "*$fuzz*"
fi