Module: Rfd::Commands
- Included in:
- Controller
- Defined in:
- lib/rfd/commands.rb
Instance Method Summary collapse
-
#- ⇒ Object
Return to the previous directory (popd).
-
#/ ⇒ Object
Search files and directories from the current directory.
-
#a ⇒ Object
Change permission (“A”ttributes) of selected files and directories.
-
#C ⇒ Object
“C”opy paths of selected files and directory to the “C”lipboard.
-
#c ⇒ Object
“c”opy selected files and directories.
-
#click(y: nil, x: nil) ⇒ Object
Move cursor position by mouse click.
-
#ctrl_a ⇒ Object
Mark or unmark “a”ll files and directories.
-
#ctrl_b ⇒ Object
“b”ack to the previous page.
-
#ctrl_f ⇒ Object
“f”orward to the next page.
-
#ctrl_l ⇒ Object
Refresh the screen.
-
#ctrl_n ⇒ Object
Forward to the “n”ext page.
-
#ctrl_p ⇒ Object
Back to the “p”revious page.
-
#ctrl_w ⇒ Object
Split the main “w”indow into given number of columns.
-
#D ⇒ Object
Hard “d”elete selected files and directories.
-
#d ⇒ Object
Soft “d”elete (actually mv to the trash folder on OSX) selected files and directories.
-
#del ⇒ Object
cd to the upper hierarchy.
-
#double_click(y: nil, x: nil) ⇒ Object
Move cursor position and enter.
-
#e ⇒ Object
Open current file or directory with the “e”ditor.
-
#enter ⇒ Object
cd into a directory, or view a file.
-
#F ⇒ Object
“f”ind the last file or directory of which name starts with the given String.
-
#f ⇒ Object
“f”ind the first file or directory of which name starts with the given String.
-
#g ⇒ Object
Move the cursor to the top of the list.
-
#G ⇒ Object
Move the cursor to the bottom of the list.
-
#H ⇒ Object
Move the cursor to the top.
-
#h ⇒ Object
Move the cursor to the left pane.
-
#j ⇒ Object
Move the cursor down.
-
#K ⇒ Object
Ma“K”e a directory.
-
#k ⇒ Object
Move the cursor up.
-
#l ⇒ Object
Move the cursor to the right pane.
-
#L ⇒ Object
Move the cursor to the bottom.
-
#m ⇒ Object
“m”ove selected files and directories.
-
#M ⇒ Object
Move the cursor to the “M”iddle.
-
#n ⇒ Object
Redo the latest f or F.
-
#O ⇒ Object
“O”pen terminal here.
-
#o ⇒ Object
“o”pen selected files and directories with the OS “open” command.
-
#p ⇒ Object
Paste yanked files / directories into the directory on which the cursor is, or into the current directory.
-
#q ⇒ Object
“q”uit the app.
-
#q! ⇒ Object
“q”uit the app!.
-
#r ⇒ Object
“r”ename selected files and directories.
-
#S ⇒ Object
“S”ymlink the current file or directory.
-
#s ⇒ Object
“s”ort displayed files and directories in the given order.
-
#space ⇒ Object
Toggle mark, and move down.
-
#T ⇒ Object
“T”ouch the current file.
-
#t ⇒ Object
Create a new file, or update its timestamp if the file already exists (“t”ouch).
-
#u ⇒ Object
“u”narchive .zip and .tar.gz files within selected files and directories into current_directory.
-
#v ⇒ Object
“o”pen selected files and directories with the viewer.
-
#w ⇒ Object
Change o“w”ner of selected files and directories.
-
#y ⇒ Object
“y”ank selected file / directory names.
-
#z ⇒ Object
Archive selected files and directories into a “z”ip file.
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 |
#a ⇒ Object
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 |
#C ⇒ Object
“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 |
#c ⇒ Object
“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_a ⇒ Object
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_b ⇒ Object
“b”ack to the previous page.
204 205 206 |
# File 'lib/rfd/commands.rb', line 204 def ctrl_b ctrl_p end |
#ctrl_f ⇒ Object
“f”orward to the next page.
209 210 211 |
# File 'lib/rfd/commands.rb', line 209 def ctrl_f ctrl_n end |
#ctrl_l ⇒ Object
Refresh the screen.
214 215 216 |
# File 'lib/rfd/commands.rb', line 214 def ctrl_l ls end |
#ctrl_n ⇒ Object
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_p ⇒ Object
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_w ⇒ Object
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 |
#D ⇒ Object
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 |
#d ⇒ Object
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 |
#del ⇒ Object
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.(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 |
#e ⇒ Object
Open current file or directory with the “e”ditor
24 25 26 |
# File 'lib/rfd/commands.rb', line 24 def e edit end |
#enter ⇒ Object
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 |
#F ⇒ Object
“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 |
#f ⇒ Object
“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 |
#g ⇒ Object
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 |
#G ⇒ Object
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 |
#H ⇒ Object
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 |
#h ⇒ Object
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 |
#j ⇒ Object
Move the cursor down.
44 45 46 |
# File 'lib/rfd/commands.rb', line 44 def j move_cursor (current_row + times) % items.size end |
#K ⇒ Object
Ma“K”e a directory.
162 163 164 |
# File 'lib/rfd/commands.rb', line 162 def K process_command_line preset_command: 'mkdir' end |
#k ⇒ Object
Move the cursor up.
49 50 51 |
# File 'lib/rfd/commands.rb', line 49 def k move_cursor (current_row - times) % items.size end |
#l ⇒ Object
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 |
#L ⇒ Object
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 |
#m ⇒ Object
“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 |
#M ⇒ Object
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 |
#n ⇒ Object
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 |
#O ⇒ Object
“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 |
#o ⇒ Object
“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 |
#p ⇒ Object
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 |
#q ⇒ Object
“q”uit the app.
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!
88 89 90 |
# File 'lib/rfd/commands.rb', line 88 def q! raise StopIteration end |
#r ⇒ Object
“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 |
#S ⇒ Object
“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 |
#s ⇒ Object
“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 |
#space ⇒ Object
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 |
#T ⇒ Object
“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 |
#t ⇒ Object
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 |
#u ⇒ Object
“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 |
#v ⇒ Object
“o”pen selected files and directories with the viewer.
113 114 115 |
# File 'lib/rfd/commands.rb', line 113 def v view end |
#w ⇒ Object
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 |
#y ⇒ Object
“y”ank selected file / directory names.
123 124 125 |
# File 'lib/rfd/commands.rb', line 123 def y yank end |
#z ⇒ Object
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 |