-
Notifications
You must be signed in to change notification settings - Fork 0
/
khoj_gdialog
executable file
·93 lines (75 loc) · 2.09 KB
/
khoj_gdialog
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
93
#!/bin/bash
###########################################################################
#
# khoj
#
# Author: mSatyam
#
# November, 2013
#
# Implements GUI Search Utility for LINUX
#
###########################################################################
# Ask user for type of search (i.e. File Search/ File Content Search)
gdialog --title "Easy Search For You" --menu "Select" 12 12 3 1 "Search Files" 2 "Search File Contents" 2> /tmp/input_$$
gdialog --clear
# Store Type Specified by user
type=$(cat /tmp/input_$$)
# Ask User for base folder to search in
gdialog --title "Easy Search For You" --inputbox "In Which Directory to Search?" 12 12 2> /tmp/input_$$
gdialog --clear
# Store Search Directory
dir=$(cat /tmp/input_$$)
# ensure that one of the two types was selected
if [ -z "$type" ]
then
echo "No Type Selected: Exiting..."
rm -rf /tmp/input_$$
exit 1
# ensure that directory name is valid
elif [ ! -d "$dir" ]
then
echo "Invalid Search Directory Entered: Exiting..."
rm -rf /tmp/input_$$
exit 2
elif [ $type -eq "1" ]
then
# Ask user for filename
gdialog --title "Easy Search For You" --inputbox "Name of file?" 12 12 2> /tmp/input_$$
gdialog --clear
# Store filename
filename=$(cat /tmp/input_$$)
# ensure filename is not null
if [ -z "$filename" ]
then
echo "Empty File Name: Exiting..."
rm -rf /tmp/input_$$
exit 3
fi
clear
# Confirm User
echo "Searching for file: \"$filename\" in directory: \"$dir\""
# Do actual search
find "$dir" -iname "$filename*" -type f 2> /dev/null
else
# Ask user for content to be looked for in a file
gdialog --title "Easy Search For You" --inputbox "Contents to look for?" 12 12 2> /tmp/input_$$
gdialog --clear
# Store Content
content=$(cat /tmp/input_$$)
# ensure Content is not null
if [ -z "$content" ]
then
echo "Empty Content to look for: Exiting..."
rm -rf /tmp/input_$$
exit 4
fi
clear
# Confirm User
echo "Searching for files having content: \"$content\" in directory: \"$dir\""
# Do actual search
find "$dir" -type f -exec grep -iHn "$content*" {} \;
fi
# clean up temporary data
rm -rf /tmp/input_$$
exit 0