bin/diru in diru-0.0.4 vs bin/diru in diru-0.0.5
- old
+ new
@@ -72,12 +72,12 @@
[
[ :switch, 'hub', nil, "H: Start hub." ],
[ :opt_single, 'hport', nil, "H: Hub port (default: DIRU_HUB_PORT or 41114)." ],
[ :switch, 'hkill', nil, "H: Kill hub." ],
[ :switch, 'nodaemon', nil, "H: No daemon for server." ],
- [ :switch, 'server', '-s', "S: Open server for client." ],
- [ :opt_single, 'kill', '-k', "S: Close server for client." ],
+ [ :opt_any, 'server', '-s', "S: Open server for user (default: $USER)." ],
+ [ :opt_single, 'kill', '-k', "S: Close server." ],
[ :switch, 'list', '-l', "S: List servers." ],
[ :opt_single, 'options', '-o', "SC: Options File." ],
[ :opt_single, 'port', '-p', "SC: Server port for client (default: DIRU_PORT or ~/.diru.prt)." ],
[ :switch, 'change', '-c', "C: Change dir (i.e. target is to change dir)." ],
[ :exclusive, 'template', '-t', "C: Display Options File template." ],
@@ -183,11 +183,11 @@
# Diru Server State.
class Search
include Diru
- def initialize( root, opts_file = nil )
+ def initialize( root, user, opts_file = nil )
# Server root.
@root = root
if @root == '/'
@rootpart = ''
@@ -196,10 +196,13 @@
end
# Change directory to DIRU root.
Dir.chdir( @root )
+ # User of server.
+ @user = user
+
# List of old matches.
@old = []
# Numbered bookmarks.
@book = []
@@ -251,20 +254,26 @@
start_th_data
start_th_opts
end
+ # Return opts_file.
def opts_file
@opts_file
end
# Return root.
def root
@root
end
+ # Return user.
+ def user
+ @user
+ end
+
# Add bookmark (if not already).
def abook( dir )
idx = @book.index dir
unless idx
@book.push dir
@@ -550,11 +559,11 @@
kill_th_opts
end
# Reset dynamic state.
- def reset
+ def reset
log "reset"
@old = []
@book = []
@hist = []
update_data_sync
@@ -679,16 +688,16 @@
end
end
# Create new server and return port for the server.
- def get_server( root, opts_file )
+ def get_server( root, user, opts_file )
50.times do |i|
if @@servers[ @port+1+i ] == nil
port = @port+1+i
- s = Service.new( root, port, opts_file )
+ s = Service.new( root, user, port, opts_file )
@@servers[ port ] = s
return port
end
end
@@ -696,11 +705,11 @@
end
# List all server ports.
def list_servers
- @@servers.keys.map{ |i| [ i, @@servers[i].root ] }
+ @@servers.keys.map{ |i| [ i, @@servers[i].root, @@servers[i].user ] }
end
# Kill all servers.
def kill_servers
@@ -727,14 +736,16 @@
# diru client service (server) thread.
class Service
attr_reader :root
+ attr_reader :user
# Initialize and start service.
- def initialize( root, port, opts_file )
+ def initialize( root, user, port, opts_file )
@root = root
+ @user = user
@port = port
@drb = nil
@opts_file = opts_file
start
self
@@ -750,11 +761,11 @@
# Start service.
def start
@th = Thread.new do
# Create "front" object.
- @search = Search.new( @root, @opts_file )
+ @search = Search.new( @root, @user, @opts_file )
# Start the service
@drb = DRb::DRbServer.new( "druby://localhost:#{@port}", @search )
@drb.thread.join
end
@@ -829,11 +840,11 @@
# Setup client server.
hub = DRbObject.new( nil, "druby://localhost:#{hport}" )
root = nil
opts_file = nil
-
+
if ENV['DIRU_ROOT']
root = ENV['DIRU_ROOT']
else
# First search for .diru_root_dir file.
begin
@@ -854,12 +865,18 @@
end
end
opts_file = Diru.get_opts_file( opts_file )
+ if Opt['server'].value.any?
+ user = Opt['server'].value[0]
+ else
+ user = ENV['USER']
+ end
+
begin
- s_port = hub.get_server( root, opts_file )
+ s_port = hub.get_server( root, user, opts_file )
rescue
Diru.error "Access to Hub failed!"
end
if s_port == 0
@@ -890,11 +907,11 @@
if Opt['list'].given
hub = DRbObject.new( nil, "druby://localhost:#{hport}" )
begin
hub.list_servers.each do |i|
- puts format( "%-12.d %s", i[0], i[1] )
+ puts format( "%-12.d %-12s %s", i[0], i[2], i[1] )
end
rescue
Diru.error "Access to Hub failed!"
end
@@ -971,10 +988,12 @@
when ':', 't'; disp @search.match( Dir.pwd, "*"+arg.join('*')+"*" )
when 'e'; disp @search.rematch( nil, arg.join('.*') )
+ when 'q'; disp @search.rematch( nil, arg.join('.*') )
+
when '.', 'b';
if arg[0] == nil
lbook( @search.book )
no_cd
elsif arg[0] == '.'
@@ -1110,10 +1129,27 @@
do_cd
end
end
+ # Display directories without CD.
+ def show( resp )
+ if resp == nil
+ # NOP
+ elsif resp.kind_of? Array
+ if resp.any?
+ resp.each do |i|
+ STDERR.puts i
+ end
+ end
+ else
+ STDERR.puts resp
+ end
+ no_cd
+ end
+
+
# Get peer directory. Search list of re-pairs. Match either of the
# pair, and switch to the pair dir.
#
def peer
cur = Dir.pwd
@@ -1132,10 +1168,11 @@
def doc
STDERR.puts "
r / - search from root (or to root)
t : - search from this (current)
e - search from root (with regexp)
+ q - query from root (with regexp)
b . - bookmark access
h , - history access
s _ - scratch pad access
p = - peer of current
c @ - command (reset, doc etc.)
@@ -1195,21 +1232,21 @@
port = ENV['DIRU_PORT'].to_i
elsif File.exist?( "#{ENV['HOME']}/.diru.prt" )
port = File.read( "#{ENV['HOME']}/.diru.prt" ).to_i
else
Diru.error "Server port info missing..."
-end
+end
# User command content.
input = Opt[nil].value
begin
client = Client.new( port )
rescue
Diru.error "Server not available!"
exit( false )
-end
+end
ret = false
begin
ret = client.command( input )
rescue