-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubyfind.rb
executable file
·54 lines (47 loc) · 1.2 KB
/
rubyfind.rb
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
#!/usr/bin/env ruby
STAT_METHODS = File::Stat.instance_methods - Object.instance_methods - Comparable.instance_methods - ["<=>"]
def find file, dir="/home/odin"
Dir.chdir(dir)
results = []
search_array = file.split("/")
last_word = search_array.last
search_array[-1] = "*"+ search_array[-1] unless search_array[-1][0] == 46
file = search_array.join("/")
search_glob = "**/"+ (file.gsub(/(\w)/, '\1*').gsub("/", '/**/'))
puts search_glob.to_s
Dir.glob(search_glob) do |filename|
results << filename
end
results.sort do |a,b|
if a.downcase.include?(last_word)
-1
elsif b.downcase.include?(last_word)
1
else
0
end
end
end
def get_input
output = `kdialog --inputbox "Query"`
output.chomp
end
def display results
results_array = []
results.first(10).each do |file|
results_array << file
results_array << file
end
`kdialog --menu "Select File:" #{results_array.join(" ")}`
end
`kdialog --msgbox #{ARGV.inspect}}`
input = get_input
if ARGV.first
results = find input, AGRV.first
`kdialog --msgbox #{results.inspect}}`
else
results = find input
`kdialog --msgbox #{results}}`
end
selection = display results
`kate -u #{selection}`