Module: Rfd::Commands

Included in:
Controller
Defined in:
lib/rfd/commands.rb

Instance Method Summary collapse

Instance Method Details

#-Object

Return to the previous directory (popd).



245
246
247
# File 'lib/rfd/commands.rb', line 245

def -
  popd
end

#/Object

Search files and directories from the current directory.



250
251
252
# File 'lib/rfd/commands.rb', line 250

def /
  process_command_line preset_command: 'grep'
end

#aObject

Change permission (“A”ttributes) of selected files and directories.



5
6
7
# File 'lib/rfd/commands.rb', line 5

def a
  process_command_line preset_command: 'chmod'
end

#CObject

“C”opy paths of selected files and directory to the “C”lipboard.



133
134
135
# File 'lib/rfd/commands.rb', line 133

def C
  clipboard
end

#cObject

“c”opy selected files and directories.



10
11
12
# File 'lib/rfd/commands.rb', line 10

def c
  process_command_line preset_command: 'cp'
end

#click(y: nil, x: nil) ⇒ Object

Move cursor position by mouse click.



300
301
302
# File 'lib/rfd/commands.rb', line 300

def click(y: nil, x: nil)
  move_cursor_by_click y: y, x: x
end

#ctrl_aObject

Mark or unmark “a”ll files and directories.



195
196
197
198
199
200
201
# File 'lib/rfd/commands.rb', line 195

def ctrl_a
  mark = marked_items.size != (items.size - 2)  # exclude . and ..
  items.each {|i| i.toggle_mark unless i.marked? == mark}
  draw_items
  draw_marked_items
  move_cursor current_row
end

#ctrl_bObject

“b”ack to the previous page.



204
205
206
# File 'lib/rfd/commands.rb', line 204

def ctrl_b
  ctrl_p
end

#ctrl_fObject

“f”orward to the next page.



209
210
211
# File 'lib/rfd/commands.rb', line 209

def ctrl_f
  ctrl_n
end

#ctrl_lObject

Refresh the screen.



214
215
216
# File 'lib/rfd/commands.rb', line 214

def ctrl_l
  ls
end

#ctrl_nObject

Forward to the “n”ext page.



219
220
221
# File 'lib/rfd/commands.rb', line 219

def ctrl_n
  move_cursor (current_page + 1) % total_pages * max_items if total_pages > 1
end

#ctrl_pObject

Back to the “p”revious page.



224
225
226
# File 'lib/rfd/commands.rb', line 224

def ctrl_p
  move_cursor (current_page - 1) % total_pages * max_items if total_pages > 1
end

#ctrl_wObject

Split the main “w”indow into given number of columns.



229
230
231
232
233
234
# File 'lib/rfd/commands.rb', line 229

def ctrl_w
  if @times
    spawn_panes @times.to_i
    ls
  end
end

#DObject

Hard “d”elete selected files and directories.



138
139
140
141
142
143
144
# File 'lib/rfd/commands.rb', line 138

def D
  if selected_items.any?
    if ask %Q[Are you sure want to delete #{selected_items.one? ? selected_items.first.name : "these #{selected_items.size} files"}? (y/n)]
      delete
    end
  end
end

#dObject

Soft “d”elete (actually mv to the trash folder on OSX) selected files and directories.



15
16
17
18
19
20
21
# File 'lib/rfd/commands.rb', line 15

def d
  if selected_items.any?
    if ask %Q[Are you sure want to trash #{selected_items.one? ? selected_items.first.name : "these #{selected_items.size} files"}? (y/n)]
      trash
    end
  end
end

#delObject

cd to the upper hierarchy.



291
292
293
294
295
296
297
# File 'lib/rfd/commands.rb', line 291

def del
  if current_dir.path != '/'
    dir_was = times == 1 ? current_dir.name : File.basename(current_dir.join(['..'] * (times - 1)))
    cd File.expand_path(current_dir.join(['..'] * times))
    find dir_was
  end
end

#double_click(y: nil, x: nil) ⇒ Object

Move cursor position and enter



305
306
307
308
309
# File 'lib/rfd/commands.rb', line 305

def double_click(y: nil, x: nil)
  if move_cursor_by_click y: y, x: x
    enter
  end
end

#eObject

Open current file or directory with the “e”ditor



24
25
26
# File 'lib/rfd/commands.rb', line 24

def e
  edit
end

#enterObject

cd into a directory, or view a file.



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/rfd/commands.rb', line 270

def enter
  if current_item.name == '.'  # do nothing
  elsif current_item.name == '..'
    cd '..'
  elsif in_zip?
    v
  elsif current_item.directory? || current_item.zip?
    cd current_item
  else
    v
  end
end

#FObject

“f”ind the last file or directory of which name starts with the given String.



147
148
149
# File 'lib/rfd/commands.rb', line 147

def F
  c = get_char and (@last_command = -> { find_reverse c }).call
end

#fObject

“f”ind the first file or directory of which name starts with the given String.



29
30
31
# File 'lib/rfd/commands.rb', line 29

def f
  c = get_char and (@last_command = -> { find c }).call
end

#gObject

Move the cursor to the top of the list.



34
35
36
# File 'lib/rfd/commands.rb', line 34

def g
  move_cursor 0
end

#GObject

Move the cursor to the bottom of the list.



157
158
159
# File 'lib/rfd/commands.rb', line 157

def G
  move_cursor items.size - 1
end

#HObject

Move the cursor to the top.



152
153
154
# File 'lib/rfd/commands.rb', line 152

def H
  move_cursor current_page * max_items
end

#hObject

Move the cursor to the left pane.



39
40
41
# File 'lib/rfd/commands.rb', line 39

def h
  (y = current_row - maxy) >= 0 and move_cursor y
end

#jObject

Move the cursor down.



44
45
46
# File 'lib/rfd/commands.rb', line 44

def j
  move_cursor (current_row + times) % items.size
end

#KObject

Ma“K”e a directory.



162
163
164
# File 'lib/rfd/commands.rb', line 162

def K
  process_command_line preset_command: 'mkdir'
end

#kObject

Move the cursor up.



49
50
51
# File 'lib/rfd/commands.rb', line 49

def k
  move_cursor (current_row - times) % items.size
end

#lObject

Move the cursor to the right pane.



54
55
56
# File 'lib/rfd/commands.rb', line 54

def l
  (y = current_row + maxy) < items.size and move_cursor y
end

#LObject

Move the cursor to the bottom.



167
168
169
# File 'lib/rfd/commands.rb', line 167

def L
  move_cursor current_page * max_items + displayed_items.size - 1
end

#mObject

“m”ove selected files and directories.



59
60
61
# File 'lib/rfd/commands.rb', line 59

def m
  process_command_line preset_command: 'mv'
end

#MObject

Move the cursor to the “M”iddle.



172
173
174
# File 'lib/rfd/commands.rb', line 172

def M
  move_cursor current_page * max_items + displayed_items.size / 2
end

#nObject

Redo the latest f or F.



64
65
66
# File 'lib/rfd/commands.rb', line 64

def n
  @last_command.call if @last_command
end

#OObject

“O”pen terminal here.



177
178
179
180
181
182
# File 'lib/rfd/commands.rb', line 177

def O
  dir = current_item.directory? ? current_item.path : current_dir.path
  system %Q[osascript -e 'tell app "Terminal"
    do script "cd #{dir}"
  end tell'] if osx?
end

#oObject

“o”pen selected files and directories with the OS “open” command.



69
70
71
72
73
74
75
# File 'lib/rfd/commands.rb', line 69

def o
  if selected_items.any?
    system "open #{selected_items.map {|i| %Q["#{i.path}"]}.join(' ')}"
  elsif %w(. ..).include? current_item.name
    system %Q[open "#{current_item.path}"]
  end
end

#pObject

Paste yanked files / directories into the directory on which the cursor is, or into the current directory.



78
79
80
# File 'lib/rfd/commands.rb', line 78

def p
  paste
end

#qObject

“q”uit the app.

Raises:

  • (StopIteration)


83
84
85
# File 'lib/rfd/commands.rb', line 83

def q
  raise StopIteration if ask 'Are you sure want to exit? (y/n)'
end

#q!Object

“q”uit the app!

Raises:

  • (StopIteration)


88
89
90
# File 'lib/rfd/commands.rb', line 88

def q!
  raise StopIteration
end

#rObject

“r”ename selected files and directories.



93
94
95
# File 'lib/rfd/commands.rb', line 93

def r
  process_command_line preset_command: 'rename'
end

#SObject

“S”ymlink the current file or directory



185
186
187
# File 'lib/rfd/commands.rb', line 185

def S
  process_command_line preset_command: 'symlink'
end

#sObject

“s”ort displayed files and directories in the given order.



98
99
100
# File 'lib/rfd/commands.rb', line 98

def s
  process_command_line preset_command: 'sort'
end

#spaceObject

Toggle mark, and move down.



284
285
286
287
288
# File 'lib/rfd/commands.rb', line 284

def space
  toggle_mark
  draw_marked_items
  j
end

#TObject

“T”ouch the current file. This updates current item’s timestamp (equivalent to ‘touch -t`).



190
191
192
# File 'lib/rfd/commands.rb', line 190

def T
  process_command_line preset_command: 'touch_t', default_argument: current_item.mtime.tr(': -', '')
end

#tObject

Create a new file, or update its timestamp if the file already exists (“t”ouch).



103
104
105
# File 'lib/rfd/commands.rb', line 103

def t
  process_command_line preset_command: 'touch'
end

#uObject

“u”narchive .zip and .tar.gz files within selected files and directories into current_directory.



108
109
110
# File 'lib/rfd/commands.rb', line 108

def u
  unarchive
end

#vObject

“o”pen selected files and directories with the viewer.



113
114
115
# File 'lib/rfd/commands.rb', line 113

def v
  view
end

#wObject

Change o“w”ner of selected files and directories.



118
119
120
# File 'lib/rfd/commands.rb', line 118

def w
  process_command_line preset_command: 'chown'
end

#yObject

“y”ank selected file / directory names.



123
124
125
# File 'lib/rfd/commands.rb', line 123

def y
  yank
end

#zObject

Archive selected files and directories into a “z”ip file.



128
129
130
# File 'lib/rfd/commands.rb', line 128

def z
  process_command_line preset_command: 'zip'
end