bin/diru in diru-0.0.3 vs bin/diru in diru-0.0.4
- old
+ new
@@ -187,10 +187,15 @@
def initialize( root, opts_file = nil )
# Server root.
@root = root
+ if @root == '/'
+ @rootpart = ''
+ else
+ @rootpart = @root
+ end
# Change directory to DIRU root.
Dir.chdir( @root )
# List of old matches.
@@ -236,10 +241,11 @@
# Lock for DB access.
@datalock = Mutex.new
@optslock = Mutex.new
+
# Initial data update.
update_conf
update_data
start_th_data
@@ -332,11 +338,11 @@
end
# Get (and update) favorite.
def gfav( tag )
- "#{@root}/#{@fav[ tag ]}"
+ "#{@rootpart}/#{@fav[ tag ]}"
end
# Return the whole fav.
def fav
@@ -395,37 +401,68 @@
def abs2rel( path )
if path == @root
''
else
- rem = "#{@root}/"
+ rem = "#{@rootpart}/"
rel = path.dup
rel[rem] = ''
rel
end
end
- # Match dir/pattern from DB.
+ # Match dir/pattern with glob (fnmatch) from DB.
def match( dir, pattern )
list = []
if dir
begin
dir = abs2rel( dir )
rescue
return []
end
+ r = dir + '*' + pattern
+ else
+ r = pattern
+ end
+
+ @datalock.synchronize do
+ @data.each do |i|
+ if File.fnmatch( r, i )
+ list.push "#{@rootpart}/#{i}"
+ end
+ end
+ end
+
+ # Update old list.
+ @old = list.rotate
+
+ list
+ end
+
+
+
+ # Match dir/pattern with regex from DB.
+ def rematch( dir, pattern )
+ list = []
+
+ if dir
+ begin
+ dir = abs2rel( dir )
+ rescue
+ return []
+ end
r = dir + '.*' + pattern
else
r = pattern
end
@datalock.synchronize do
@data.each do |i|
if i.match( r )
- list.push "#{@root}/#{i}"
+ list.push "#{@rootpart}/#{i}"
end
end
end
# Update old list.
@@ -912,11 +949,11 @@
else
cmd = input[0]
arg = input[1..-1]
- # Shell specials chars to prevent:
+ # Shell special chars to avoid:
# * ? [ ] ' " \ $ ; & ( ) | ^ < >
# Thus allowed:
# ! % + , - . / : = @ _ ~
# ^ ^ ^ ^ ^ ^ ^ ^ ^
@@ -927,15 +964,17 @@
when '/', 'r';
if arg.empty?
disp @search.root
else
- disp @search.match( nil, arg.join('.*') )
+ disp @search.match( nil, "*"+arg.join('*')+"*" )
end
- when ':', 't'; disp @search.match( Dir.pwd, arg.join('.*') )
+ when ':', 't'; disp @search.match( Dir.pwd, "*"+arg.join('*')+"*" )
+ when 'e'; disp @search.rematch( nil, arg.join('.*') )
+
when '.', 'b';
if arg[0] == nil
lbook( @search.book )
no_cd
elsif arg[0] == '.'
@@ -1092,9 +1131,10 @@
# Display short command doc.
def doc
STDERR.puts "
r / - search from root (or to root)
t : - search from this (current)
+ e - search from root (with regexp)
b . - bookmark access
h , - history access
s _ - scratch pad access
p = - peer of current
c @ - command (reset, doc etc.)