rfd 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rfd +4 -1
- data/lib/rfd.rb +23 -7
- data/lib/rfd/commands.rb +5 -0
- data/lib/rfd/item.rb +3 -5
- data/lib/rfd/logging.rb +34 -0
- data/lib/rfd/windows.rb +21 -7
- data/rfd.gemspec +3 -3
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84197fc407fef60acd2692a461619061d05c114d57bed5d6454d0f726df88475
|
4
|
+
data.tar.gz: 5b3f4027252840d90e600f9f4b67c7d287f3c56b7f9611f51c58d9b9d5601b02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74abcf3216b07f522d18d7061a6347a8255198e4377c54b210a54401c578372a4111931c46f4abaff98a7f35965b747fa3033e8c4dc5c565edd482a4dc928f81
|
7
|
+
data.tar.gz: 1d34bae5303921385f0bdc181f8b140817034027f10962c8840d2e9b317210999d454b7e27520e034ccab18f5eb02ef56c3afb7141c4e9b6b8dd0a1ec64f5e24
|
data/bin/rfd
CHANGED
data/lib/rfd.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'curses'
|
3
3
|
require 'fileutils'
|
4
|
+
require 'time'
|
4
5
|
require 'tmpdir'
|
5
6
|
require 'rubygems/package'
|
6
7
|
require 'zip'
|
@@ -8,9 +9,10 @@ require 'zip/filesystem'
|
|
8
9
|
require_relative 'rfd/commands'
|
9
10
|
require_relative 'rfd/item'
|
10
11
|
require_relative 'rfd/windows'
|
12
|
+
require_relative 'rfd/logging'
|
11
13
|
|
12
14
|
module Rfd
|
13
|
-
VERSION = Gem.loaded_specs['rfd'].version.to_s
|
15
|
+
VERSION = Gem.loaded_specs['rfd'] ? Gem.loaded_specs['rfd'].version.to_s : '0'
|
14
16
|
|
15
17
|
# :nodoc:
|
16
18
|
def self.init_curses
|
@@ -32,7 +34,9 @@ module Rfd
|
|
32
34
|
#
|
33
35
|
# ==== Parameters
|
34
36
|
# * +dir+ - The initial directory.
|
35
|
-
def self.start(dir = '.')
|
37
|
+
def self.start(dir = '.', log: nil)
|
38
|
+
Rfd.log_to log if log
|
39
|
+
|
36
40
|
init_curses
|
37
41
|
Rfd::Window.draw_borders
|
38
42
|
Curses.stdscr.noutrefresh
|
@@ -108,6 +112,7 @@ module Rfd
|
|
108
112
|
rescue StopIteration
|
109
113
|
raise
|
110
114
|
rescue => e
|
115
|
+
Rfd.logger.error e if Rfd.logger
|
111
116
|
command_line.show_error e.to_s
|
112
117
|
raise if ENV['DEBUG']
|
113
118
|
end
|
@@ -467,7 +472,9 @@ module Rfd
|
|
467
472
|
zip.instance_variable_get(:@entry_set) << Zip::Entry.new(current_zip, filename)
|
468
473
|
end
|
469
474
|
end
|
475
|
+
|
470
476
|
ls
|
477
|
+
move_cursor items.index {|i| i.name == filename}
|
471
478
|
end
|
472
479
|
|
473
480
|
# Create a symlink to the current file or directory.
|
@@ -476,6 +483,15 @@ module Rfd
|
|
476
483
|
ls
|
477
484
|
end
|
478
485
|
|
486
|
+
# Change the timestamp of the selected files and directories.
|
487
|
+
#
|
488
|
+
# ==== Parameters
|
489
|
+
# * +timestamp+ - A string that can be parsed with `Time.parse`. Note that this parameter is not compatible with UNIX `touch -t`.
|
490
|
+
def touch_t(timestamp)
|
491
|
+
FileUtils.touch selected_items, mtime: Time.parse(timestamp)
|
492
|
+
ls
|
493
|
+
end
|
494
|
+
|
479
495
|
# Yank selected file / directory names.
|
480
496
|
def yank
|
481
497
|
@yanked_items = selected_items
|
@@ -554,7 +570,7 @@ module Rfd
|
|
554
570
|
end
|
555
571
|
dest ||= File.join dest_dir, entry.full_name
|
556
572
|
if entry.directory?
|
557
|
-
FileUtils.mkdir_p dest, :
|
573
|
+
FileUtils.mkdir_p dest, mode: entry.header.mode
|
558
574
|
elsif entry.file?
|
559
575
|
FileUtils.mkdir_p dest_dir
|
560
576
|
File.open(dest, 'wb') {|f| f.print entry.read}
|
@@ -638,10 +654,11 @@ module Rfd
|
|
638
654
|
#
|
639
655
|
# ==== Parameters
|
640
656
|
# * +preset_command+ - A command that would be displayed at the command line before user input.
|
641
|
-
|
657
|
+
# * +default_argument+ - A default argument for the command.
|
658
|
+
def process_command_line(preset_command: nil, default_argument: nil)
|
642
659
|
prompt = preset_command ? ":#{preset_command} " : ':'
|
643
660
|
command_line.set_prompt prompt
|
644
|
-
cmd, *args = command_line.get_command(prompt: prompt).split(' ')
|
661
|
+
cmd, *args = command_line.get_command(prompt: prompt, default: default_argument).split(' ')
|
645
662
|
if cmd && !cmd.empty? && respond_to?(cmd)
|
646
663
|
ret = self.public_send cmd, *args
|
647
664
|
clear_command_line
|
@@ -673,8 +690,7 @@ module Rfd
|
|
673
690
|
command_line.refresh
|
674
691
|
while (c = Curses.getch)
|
675
692
|
next unless [?N, ?Y, ?n, ?y, 3, 27] .include? c # N, Y, n, y, ^c, esc
|
676
|
-
|
677
|
-
command_line.noutrefresh
|
693
|
+
clear_command_line
|
678
694
|
break (c == 'y') || (c == 'Y')
|
679
695
|
end
|
680
696
|
end
|
data/lib/rfd/commands.rb
CHANGED
@@ -186,6 +186,11 @@ module Rfd
|
|
186
186
|
process_command_line preset_command: 'symlink'
|
187
187
|
end
|
188
188
|
|
189
|
+
# "T"ouch the current file. This updates current item's timestamp (equivalent to `touch -t`).
|
190
|
+
def T
|
191
|
+
process_command_line preset_command: 'touch_t', default_argument: current_item.mtime.tr(': -', '')
|
192
|
+
end
|
193
|
+
|
189
194
|
# Mark or unmark "a"ll files and directories.
|
190
195
|
def ctrl_a
|
191
196
|
mark = marked_items.size != (items.size - 2) # exclude . and ..
|
data/lib/rfd/item.rb
CHANGED
@@ -37,12 +37,10 @@ module Rfd
|
|
37
37
|
n = full_display_name
|
38
38
|
if mb_size(n) <= @window_width - 15
|
39
39
|
n
|
40
|
+
elsif symlink?
|
41
|
+
mb_left n, @window_width - 16
|
40
42
|
else
|
41
|
-
|
42
|
-
mb_left n, @window_width - 16
|
43
|
-
else
|
44
|
-
"#{mb_left(basename, @window_width - 16 - extname.size)}…#{extname}"
|
45
|
-
end
|
43
|
+
"#{mb_left(basename, @window_width - 16 - extname.size)}…#{extname}"
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
data/lib/rfd/logging.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Rfd
|
6
|
+
@logger = nil
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def log_to(file)
|
10
|
+
@logger = Logger.new file
|
11
|
+
@logger.debug 'hello'
|
12
|
+
|
13
|
+
Rfd::Controller.include Logging
|
14
|
+
end
|
15
|
+
|
16
|
+
def log(str)
|
17
|
+
Rfd.logger.debug str if Rfd.logger
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :logger
|
21
|
+
end
|
22
|
+
|
23
|
+
module Logging
|
24
|
+
def self.included(m)
|
25
|
+
mod = Module.new do
|
26
|
+
(m.instance_methods - Object.instance_methods).each do |meth|
|
27
|
+
Rfd.logger.info meth
|
28
|
+
define_method(meth) {|*args, &block| Rfd.logger.debug "calling #{meth}(#{args.inspect})"; super(*args, &block) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
m.prepend mod
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/rfd/windows.rb
CHANGED
@@ -56,12 +56,12 @@ module Rfd
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def draw_marked_items(count: 0, size: 0)
|
59
|
-
writeln 0, %Q[#{"#{count}Marked".rjust(11)} #{size.to_s.reverse.gsub(
|
59
|
+
writeln 0, %Q[#{"#{count}Marked".rjust(11)} #{size.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse.rjust(16)}]
|
60
60
|
noutrefresh
|
61
61
|
end
|
62
62
|
|
63
63
|
def draw_total_items(count: 0, size: 0)
|
64
|
-
writeln 1, %Q[#{"#{count}Files".rjust(10)} #{size.to_s.reverse.gsub(
|
64
|
+
writeln 1, %Q[#{"#{count}Files".rjust(10)} #{size.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse.rjust(17)}]
|
65
65
|
noutrefresh
|
66
66
|
end
|
67
67
|
end
|
@@ -147,15 +147,29 @@ module Rfd
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
def getstr_with_echo
|
151
|
-
str =
|
150
|
+
def getstr_with_echo(default = nil)
|
151
|
+
str = default || ''.dup
|
152
|
+
|
153
|
+
unless str.empty?
|
154
|
+
self << str
|
155
|
+
refresh
|
156
|
+
end
|
157
|
+
|
152
158
|
loop do
|
153
159
|
case (c = Curses.getch)
|
154
|
-
when 27
|
160
|
+
when 27, 3 # ESC, C-c
|
155
161
|
raise Interrupt
|
156
162
|
when 10, 13
|
157
163
|
break
|
164
|
+
when 127, 263 # delete
|
165
|
+
raise Interrupt if curx == 1
|
166
|
+
|
167
|
+
setpos cury, curx - 1
|
168
|
+
delch
|
169
|
+
refresh
|
170
|
+
str.chop!
|
158
171
|
else
|
172
|
+
Rfd.log "#{__method__}: #{c}"
|
159
173
|
self << c
|
160
174
|
refresh
|
161
175
|
str << c
|
@@ -164,10 +178,10 @@ module Rfd
|
|
164
178
|
str
|
165
179
|
end
|
166
180
|
|
167
|
-
def get_command(prompt: nil)
|
181
|
+
def get_command(prompt: nil, default: nil)
|
168
182
|
startx = prompt ? prompt.size : 1
|
169
183
|
setpos 0, startx
|
170
|
-
s = getstr_with_echo
|
184
|
+
s = getstr_with_echo default
|
171
185
|
"#{prompt[1..-1] if prompt}#{s.strip}"
|
172
186
|
end
|
173
187
|
|
data/rfd.gemspec
CHANGED
@@ -5,10 +5,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rfd"
|
8
|
-
spec.version = '0.
|
8
|
+
spec.version = '0.7.0'
|
9
9
|
spec.authors = ["Akira Matsuda"]
|
10
10
|
spec.email = ["ronnie@dio.jp"]
|
11
|
-
spec.description = 'Ruby
|
11
|
+
spec.description = 'A Ruby filer that runs on terminal'
|
12
12
|
spec.summary = 'Ruby on Files & Directories'
|
13
13
|
spec.homepage = 'https://github.com/amatsuda/rfd'
|
14
14
|
spec.license = "MIT"
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'curses', '>= 1.0.0'
|
22
22
|
spec.add_dependency 'rubyzip', '>= 1.0.0'
|
23
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency "rake", "< 11.0"
|
25
25
|
spec.add_development_dependency 'rspec', "< 2.99"
|
26
26
|
end
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "<"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.99'
|
83
|
-
description: Ruby
|
83
|
+
description: A Ruby filer that runs on terminal
|
84
84
|
email:
|
85
85
|
- ronnie@dio.jp
|
86
86
|
executables:
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/rfd.rb
|
98
98
|
- lib/rfd/commands.rb
|
99
99
|
- lib/rfd/item.rb
|
100
|
+
- lib/rfd/logging.rb
|
100
101
|
- lib/rfd/windows.rb
|
101
102
|
- rfd.gemspec
|
102
103
|
- spec/controller_spec.rb
|
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
|
-
rubygems_version: 3.0.
|
140
|
+
rubygems_version: 3.0.3
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: Ruby on Files & Directories
|