rfd 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c84b042ee4196d959b2aa91af8c59ca9fa3b28b
4
- data.tar.gz: 46504bdc73c1b0f8a1779955f455e09fe73bc06a
3
+ metadata.gz: 69382b24587d8b96f6e478174154cec5789aee94
4
+ data.tar.gz: 0358469e32e915327f17bcd8f5ea379449ffc3c9
5
5
  SHA512:
6
- metadata.gz: 538534dad4ea1aadd91e06c02ad6ed31b794e25de2460f4329120e7a1988bded79d7086eb8983d479302db4a9e0d751d68129f3e73ad2238fdf80c25a141bca1
7
- data.tar.gz: b15391a9ca20f6a2d171542fd0fa3aa92f077471cc43d963ab6182fe75146e9607315a6d7f08710381e04fd21ab059040504a193c1c1840e2c1b09105812d330
6
+ metadata.gz: 977b478de382705aaced23f74ae8714f796d3d8d1e92a073c0dcb6e5fda07b9b3ff33f375598143d5fb433e6f2a151bcfbc86cee97cd5f56f24295de0e207d24
7
+ data.tar.gz: f70b35ab1d5a592c13d3540f2b4dd92cc3cac1c56415b6a64d8fcedf6903212b4dc7c41d657fc64921534120b058548e040af2069022cc89752a31ac752ca0b3
data/lib/rfd/item.rb CHANGED
@@ -4,8 +4,9 @@ module Rfd
4
4
  attr_reader :name, :dir, :stat
5
5
  attr_accessor :index
6
6
 
7
- def initialize(dir: nil, name: nil, stat: nil, window_width: nil)
8
- @dir, @name, @stat, @window_width, @marked = dir, name, stat, window_width, false
7
+ def initialize(path: nil, dir: nil, name: nil, stat: nil, window_width: nil)
8
+ @path, @dir, @name, @stat, @window_width, @marked = path, dir || File.dirname(path), name || File.basename(path), stat, window_width, false
9
+ @stat = File.lstat self.path unless stat
9
10
  end
10
11
 
11
12
  def path
@@ -127,10 +128,8 @@ module Rfd
127
128
  @zip_ ||= begin
128
129
  if directory?
129
130
  false
130
- elsif symlink?
131
- File.binread(target, 4).unpack('V').first == 0x04034b50
132
131
  else
133
- File.binread(path, 4).unpack('V').first == 0x04034b50
132
+ File.binread(realpath, 4).unpack('V').first == 0x04034b50
134
133
  end
135
134
  rescue
136
135
  false
@@ -141,10 +140,8 @@ module Rfd
141
140
  @gz_ ||= begin
142
141
  if directory?
143
142
  false
144
- elsif symlink?
145
- File.binread(target, 2).unpack('n').first == 0x1f8b
146
143
  else
147
- File.binread(path, 2).unpack('n').first == 0x1f8b
144
+ File.binread(realpath, 2).unpack('n').first == 0x1f8b
148
145
  end
149
146
  rescue
150
147
  false
@@ -155,6 +152,10 @@ module Rfd
155
152
  File.readlink path if symlink?
156
153
  end
157
154
 
155
+ def realpath
156
+ @realpath ||= File.realpath path
157
+ end
158
+
158
159
  def toggle_mark
159
160
  unless %w(. ..).include? name
160
161
  @marked = !@marked
data/lib/rfd/windows.rb CHANGED
@@ -76,7 +76,7 @@ module Rfd
76
76
  attr_reader :current_index, :begy
77
77
  attr_writer :number_of_panes
78
78
 
79
- def initialize(dir = '.')
79
+ def initialize
80
80
  @begy, @current_index, @number_of_panes = 5, 0, 2
81
81
  super window: Curses::Pad.new(Curses.lines - 7, Curses.cols - 2)
82
82
  end
@@ -127,10 +127,7 @@ module Rfd
127
127
  end
128
128
 
129
129
  def toggle_mark(item)
130
- if item.toggle_mark
131
- setpos item.index % maxy, 0
132
- self << item.current_mark
133
- end
130
+ item.toggle_mark
134
131
  end
135
132
  end
136
133
 
data/lib/rfd.rb CHANGED
@@ -169,7 +169,7 @@ module Rfd
169
169
 
170
170
  # Change the current directory.
171
171
  def cd(dir = '~', pushd: true)
172
- dir = load_item expand_path(dir) unless dir.is_a? Item
172
+ dir = load_item path: expand_path(dir) unless dir.is_a? Item
173
173
  unless dir.zip?
174
174
  Dir.chdir dir
175
175
  @current_zip = nil
@@ -254,17 +254,16 @@ module Rfd
254
254
  def fetch_items_from_filesystem_or_zip
255
255
  unless in_zip?
256
256
  @items = Dir.foreach(current_dir).map {|fn|
257
- stat = File.lstat current_dir.join(fn)
258
- Item.new dir: current_dir, name: fn, stat: stat, window_width: main.width
257
+ load_item dir: current_dir, name: fn
259
258
  }.to_a.partition {|i| %w(. ..).include? i.name}.flatten
260
259
  else
261
- @items = [Item.new(dir: current_dir, name: '.', stat: File.stat(current_dir), window_width: main.width),
262
- Item.new(dir: current_dir, name: '..', stat: File.stat(File.dirname(current_dir)), window_width: main.width)]
260
+ @items = [load_item(dir: current_dir, name: '.', stat: File.stat(current_dir)),
261
+ load_item(dir: current_dir, name: '..', stat: File.stat(File.dirname(current_dir)))]
263
262
  zf = Zip::File.new current_dir
264
263
  zf.each {|entry|
265
264
  next if entry.name_is_directory?
266
265
  stat = zf.file.stat entry.name
267
- @items << Item.new(dir: current_dir, name: entry.name, stat: stat, window_width: main.width)
266
+ @items << load_item(dir: current_dir, name: entry.name, stat: stat)
268
267
  }
269
268
  end
270
269
  end
@@ -281,11 +280,6 @@ module Rfd
281
280
  move_cursor items.size - index - 1 if index
282
281
  end
283
282
 
284
- # Width of the currently active pane.
285
- def maxx
286
- main.maxx
287
- end
288
-
289
283
  # Height of the currently active pane.
290
284
  def maxy
291
285
  main.maxy
@@ -348,6 +342,7 @@ module Rfd
348
342
  fetch_items_from_filesystem_or_zip
349
343
  @items = items.shift(2) + items.select {|i| i.name =~ regexp}
350
344
  sort_items_according_to_current_direction
345
+ draw_items
351
346
  switch_page 0
352
347
  move_cursor 0
353
348
 
@@ -489,7 +484,7 @@ module Rfd
489
484
  if items.include? item
490
485
  i = 1
491
486
  while i += 1
492
- new_item = Item.new dir: current_dir, name: "#{item.basename}_#{i}#{item.extname}", stat: item.stat, window_width: maxx
487
+ new_item = load_item dir: current_dir, name: "#{item.basename}_#{i}#{item.extname}", stat: item.stat
493
488
  break unless File.exist? new_item.path
494
489
  end
495
490
  FileUtils.cp_r item, new_item
@@ -745,9 +740,8 @@ module Rfd
745
740
  File.expand_path path.start_with?('/') || path.start_with?('~') ? path : current_dir ? current_dir.join(path) : path
746
741
  end
747
742
 
748
- def load_item(path)
749
- stat = File.lstat path
750
- Item.new dir: File.dirname(path), name: File.basename(path), stat: stat, window_width: maxx
743
+ def load_item(path: nil, dir: nil, name: nil, stat: nil)
744
+ Item.new dir: dir || File.dirname(path), name: name || File.basename(path), stat: stat, window_width: main.width
751
745
  end
752
746
 
753
747
  def osx?
data/rfd.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rfd"
7
- spec.version = '0.6.0'
7
+ spec.version = '0.6.1'
8
8
  spec.authors = ["Akira Matsuda"]
9
9
  spec.email = ["ronnie@dio.jp"]
10
10
  spec.description = 'Ruby on Files & Directories'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-22 00:00:00.000000000 Z
11
+ date: 2013-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip