cetus 0.1.18 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +10 -6
  3. data/bin/cetus +245 -147
  4. data/cetus.gemspec +1 -1
  5. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 246a8dbece2062ca2eadcd89e8c58f83347d9834
4
- data.tar.gz: 496c240c085f96cf844ff9f0c87a993e5ef79af6
2
+ SHA256:
3
+ metadata.gz: 3e35fd2792cfb584909c6ddadfaeb6b30e92ff09b4f838585a85f8de977c333e
4
+ data.tar.gz: f2b2f7e300a593f9ba2973d8451f4148f9057c5bc4680ad3c9ac77075ae6f19e
5
5
  SHA512:
6
- metadata.gz: f8646f38eda77d0f87fda7b0108bbdc1ec65151a5b2263d2582fd1962613c9937a1444cb1e14c9b6f3a9cc494e931fa229d0293915695e5c52dabc4fe3449f00
7
- data.tar.gz: ff0e0990662af40fac5e1a204d2d2247d64c8907d1cc831f9ca0c65b541afcd3866b186f5f685ed8caf558a108a8732177578f7822d434fdd051e5a3597a4508
6
+ metadata.gz: 6ab765cb054741e0d6951040d7b655d7235d1c583646c96f8bd1b12d74778fd05a735b0a3864e3f87e4b1652316a3bef6b966745bba3d3efe113d46cde306826
7
+ data.tar.gz: 1d723a6b666671544a081e426ecf34df28a6fa02bd158fed08f9c89873dbef12a050f66caf286f3231847aa622783abcb41da1285ce0b75104a9fe999658ee1c
data/README.md CHANGED
@@ -6,6 +6,10 @@ lightning-fast file navigator
6
6
  Tested with ruby 2.5
7
7
 
8
8
  Latest changes:
9
+ 2019-03-04 - q is quit key, not Q
10
+ - show directories first, then files.
11
+ - trying not to pollute main screen with listings.
12
+
9
13
  2018-03-12 - now using LEFT and RIGHT arrow keys to go down into a directory, or up to higher directory.
10
14
  Also, pressing RIGHT ARROW on a file with open the file.
11
15
  Previously RIGHT and LEFT arrows would move to next or previous columns, i have put this on left and right square bracket.
@@ -40,7 +44,7 @@ You can bind other capital letters to any external command. If there are selecte
40
44
  The rest is similar to lyra. Some key points are highlighted here.
41
45
 
42
46
  * Create bookmarks for often used directories using Alt-m. Then access them using single-quote and upper character.
43
- You have to be inside the directory when saving a new bookmark. e.g. `'P`. This is a fast way of jumping directories. I've got "P" mapped to projects, and "Z" to zfm, and so forth.
47
+ You have to be inside the directory when saving a new bookmark. e.g. `'P`. This is a fast way of jumping directories. I've got "P" mapped to projects, and "Z" to zfm, and so forth.
44
48
 
45
49
  * Single-quote and small letter jumps to the first file starting with given letter. e.g. `'s`
46
50
 
@@ -48,7 +52,7 @@ The rest is similar to lyra. Some key points are highlighted here.
48
52
 
49
53
  * Backtick is the main menu, which has options for sorting, filtering, seeing often used dirs and files, choosing from dirs in the `z` database, choosing used files from the `.viminfo` file, etc.
50
54
 
51
- Other than using bookmarks, you can jump quickly to other directories or open files using BACKTICK and the releant option which should become part of muscle memory very fast.
55
+ Other than using bookmarks, you can jump quickly to other directories or open files using BACKTICK and the releant option which should become part of muscle memory very fast.
52
56
 
53
57
  * Use Alt-d and Alt-f to see used directories and used files. Used directories are those dirs in which you have opened a file, not all dirs you've traversed. Certain directories are added to this list to make it more useful such as GEM_HOME, RUBYPATH, GEM_PATH, RUBYLIB, PYTHONPATH and PYTHONHOME.
54
58
 
@@ -56,7 +60,7 @@ Other than using bookmarks, you can jump quickly to other directories or open fi
56
60
 
57
61
  * Switch between editor mode and page mode. OFten you wish to quickly view files (maybe for deleting or moving). You don't want these files to get listed in .viminfo. Switching to pager mode, invokes your $MANPAGER on selected files which makes navigation faster. Set `most` to your MANPAGER.
58
62
 
59
- * use Alt+ and Alt- to increase or decrease the number of columns shown on screen. By default 3 are shown.
63
+ * use Alt+ and Alt- to increase or decrease the number of columns shown on screen. By default 3 are shown.
60
64
 
61
65
  * Use '=' to toggle hidden files, long listing, ignore case , pager/editor mode, etc.
62
66
 
@@ -80,14 +84,14 @@ Thus, F2 gives only child dirs in current dir, F3 gives recursive directories an
80
84
  * Note that I use readline for most entries, so you can press UP arrow to get previous entries.
81
85
 
82
86
  * A new enhanced list mode (Which can be toggled off), which tries to add more files to the list if there are very few shown:
83
- - it detects a rubygem dir and shows a few recent files from bin and lib
87
+ - it detects a rubygem dir and shows a few recent files from bin and lib
84
88
  - if there's only one file in the dir and it is a dir, it expands it
85
89
  - if there are less than 15 files in list, it gets the recently modified and recently accessed
86
90
  dir/s and shows the most recent file from each.
87
91
 
88
92
  ## Requirements ##
89
93
 
90
- Requires ruby 1.9.3, and uses zsh for globbing.
94
+ Requires ruby 1.9.3, and uses zsh for globbing.
91
95
  Uses $EDITOR and $MANPAGER or $PAGER.
92
96
 
93
97
  Optionally uses ack, locate, find for options with that name. You may replace ack with ag or other.
@@ -105,7 +109,7 @@ Copy cetus to somewhere on your path, e.g. $HOME/bin
105
109
 
106
110
  $ c
107
111
 
108
- Or :
112
+ Or :
109
113
 
110
114
  gem install cetus
111
115
  alias c=cetus
data/bin/cetus CHANGED
@@ -2,91 +2,101 @@
2
2
  # ----------------------------------------------------------------------------- #
3
3
  # File: cetus
4
4
  # Description: Fast file navigation, a tiny version of zfm
5
- # but with a diffrent indexing mechanism
5
+ # but with a different indexing mechanism
6
6
  # Author: rkumar http://github.com/rkumar/cetus/
7
7
  # Date: 2013-02-17 - 17:48
8
8
  # License: GPL
9
- # Last update: 2019-01-19 15:09
9
+ # Last update: 2019-03-04 23:50
10
10
  # ----------------------------------------------------------------------------- #
11
11
  # cetus.rb Copyright (C) 2012-2013 rahul kumar
12
+ # == CHANGELOG
13
+ # 2019-02-20 - added smcup and rmcup so alt-screen is used. works a bit
14
+ # 2019-03-04 - change clear to go to 0,0 and clear down to reduce pollution
15
+ # 2019-03-04 - changed quit to q (earlier Q)
16
+ # 2019-03-04 - first dirs then files
12
17
  # == TODO
13
- # To dirs add GEMHOME RUBYLIB PYTHONILB or PYTHONPATH,
18
+ # To dirs add GEMHOME RUBYLIB PYTHONILB or PYTHONPATH,
14
19
  # Make rubygem aware : gemspec or Gemfile the expand lib and bin
15
20
  # fpath if existing
21
+
16
22
  require 'readline'
17
23
  require 'io/wait'
18
24
  # http://www.ruby-doc.org/stdlib-1.9.3/libdoc/shellwords/rdoc/Shellwords.html
19
25
  require 'shellwords'
20
26
  require 'fileutils'
21
27
  # -- requires 1.9.3 for io/wait
22
- # -- cannot do with Highline since we need a timeout on wait, not sure if HL can do that
28
+ # -- cannot do with Highline since we need a timeout on wait,
29
+ # not sure if HL can do that
23
30
 
24
31
  ## INSTALLATION
25
32
  # copy into PATH
26
33
  # alias c=~/bin/cetus.rb
27
34
  # c
28
- VERSION="0.1.18"
29
- O_CONFIG=true
30
- CONFIG_FILE="~/.lyrainfo"
35
+
36
+ # 2019-02-20 - added so alt-screen is used
37
+ system 'tput smcup'
38
+ VERSION = '0.1.21.0'
39
+ O_CONFIG = true
40
+ CONFIG_FILE = '~/.lyrainfo'
31
41
 
32
42
  $bindings = {}
33
43
  $bindings = {
34
- "`" => "main_menu",
35
- "=" => "toggle_menu",
36
- "!" => "command_mode",
37
- "@" => "selection_mode_toggle",
38
- "M-a" => "select_all",
39
- "M-A" => "unselect_all",
40
- "," => "goto_parent_dir",
41
- "+" => "goto_dir",
42
- "." => "pop_dir",
43
- ":" => "subcommand",
44
- "'" => "goto_bookmark",
45
- "/" => "enter_regex",
46
- "M-p" => "prev_page",
47
- "M-n" => "next_page",
48
- "SPACE" => "next_page",
49
- "M-f" => "select_visited_files",
50
- "M-d" => "select_used_dirs",
51
- "M-b" => "select_bookmarks",
52
- "M-m" => "create_bookmark",
53
- "M-M" => "show_marks",
54
- "C-c" => "escape",
55
- "ESCAPE" => "escape",
56
- "TAB" => "views",
57
- "C-i" => "views",
58
- "?" => "dirtree",
59
- "ENTER" => "select_current",
60
- "D" => "delete_file",
61
- "M" => "file_actions most",
62
- "Q" => "quit_command",
44
+ '`' => 'main_menu',
45
+ '=' => 'toggle_menu',
46
+ '!' => 'command_mode',
47
+ '@' => 'selection_mode_toggle',
48
+ 'M-a' => 'select_all',
49
+ 'M-A' => 'unselect_all',
50
+ ',' => 'goto_parent_dir',
51
+ '+' => 'goto_dir',
52
+ '.' => 'pop_dir',
53
+ ':' => 'subcommand',
54
+ "'" => 'goto_bookmark',
55
+ '/' => 'enter_regex',
56
+ 'M-p' => 'prev_page',
57
+ 'M-n' => 'next_page',
58
+ 'SPACE' => 'next_page',
59
+ 'M-f' => 'select_visited_files',
60
+ 'M-d' => 'select_used_dirs',
61
+ 'M-b' => 'select_bookmarks',
62
+ 'M-m' => 'create_bookmark',
63
+ 'M-M' => 'show_marks',
64
+ 'C-c' => 'escape',
65
+ 'ESCAPE' => 'escape',
66
+ 'TAB' => 'views',
67
+ 'C-i' => 'views',
68
+ '?' => 'dirtree',
69
+ 'ENTER' => 'select_current',
70
+ 'D' => 'delete_file',
71
+ 'M' => 'file_actions most',
72
+ 'q' => 'quit_command', # was Q now q 2019-03-04 -
63
73
  #"RIGHT" => "column_next",
64
- "RIGHT" => "select_current", # changed 2018-03-12 - for faster navigation
65
- "LEFT" => "goto_parent_dir", # changed on 2018-03-12 - earlier column_next 1
66
- "]" => "column_next",
67
- "[" => "column_next 1",
68
- "C-x" => "file_actions",
69
- "M--" => "columns_incdec -1",
70
- "M-+" => "columns_incdec 1",
71
- "S" => "command_file list y ls -lh",
72
- "L" => "command_file Page n less",
73
- "C-d" => "cursor_scroll_dn",
74
- "C-b" => "cursor_scroll_up",
75
- "UP" => "cursor_up",
76
- "DOWN" => "cursor_dn",
77
- "C-SPACE" => "visual_mode_toggle",
78
-
79
- "M-?" => "print_help",
80
- "F1" => "print_help",
81
- "F2" => "child_dirs",
82
- "F3" => "dirtree",
83
- "F4" => "tree",
84
- "S-F1" => "dirtree",
85
- "S-F2" => "tree"
74
+ 'RIGHT' => 'select_current', # changed 2018-03-12 - for faster navigation
75
+ 'LEFT' => 'goto_parent_dir', # changed on 2018-03-12 - earlier column_next 1
76
+ ']' => 'column_next',
77
+ '[' => 'column_next 1',
78
+ 'C-x' => 'file_actions',
79
+ 'M--' => 'columns_incdec -1',
80
+ 'M-+' => 'columns_incdec 1',
81
+ 'S' => 'command_file list y ls -lh',
82
+ 'L' => 'command_file Page n less',
83
+ 'C-d' => 'cursor_scroll_dn',
84
+ 'C-b' => 'cursor_scroll_up',
85
+ 'UP' => 'cursor_up',
86
+ 'DOWN' => 'cursor_dn',
87
+ 'C-SPACE' => 'visual_mode_toggle',
88
+
89
+ 'M-?' => 'print_help',
90
+ 'F1' => 'print_help',
91
+ 'F2' => 'child_dirs',
92
+ 'F3' => 'dirtree',
93
+ 'F4' => 'tree',
94
+ 'S-F1' => 'dirtree',
95
+ 'S-F2' => 'tree'
86
96
 
87
97
  }
88
98
 
89
- ## clean this up a bit, copied from shell program and macro'd
99
+ ## clean this up a bit, copied from shell program and macro'd
90
100
  $kh=Hash.new
91
101
  $kh["OP"]="F1"
92
102
  $kh[""]="UP"
@@ -109,8 +119,8 @@ $kh[KEY_END]="End"
109
119
  $kh[KEY_F1]="F1"
110
120
  $kh[KEY_UP]="UP"
111
121
  $kh[KEY_DOWN]="DOWN"
112
- KEY_LEFT=''
113
- KEY_RIGHT=''
122
+ KEY_LEFT=''
123
+ KEY_RIGHT=''
114
124
  $kh["OQ"]="F2"
115
125
  $kh["OR"]="F3"
116
126
  $kh["OS"]="F4"
@@ -133,53 +143,109 @@ $kh[KEY_F10]="F10"
133
143
  $kh[KEY_S_F1]="S-F1"
134
144
  $kh['']="S-F2"
135
145
 
146
+ def old_clear_screen
147
+ system 'clear'
148
+ return
149
+ system('tput cup 0 0')
150
+ # system 'tput ed'
151
+ print "\e[J"
152
+ end
153
+
154
+ # copied from fff
155
+ def clear_screen
156
+ # Only clear the scrolling window (dir item list).
157
+ # '\e[%sH': Move cursor to bottom of scroll area.
158
+ # '\e[9999C': Move cursor to right edge of the terminal.
159
+ # '\e[1J': Clear screen to top left corner (from cursor up).
160
+ # '\e[2J': Clear screen fully (if using tmux) (fixes clear issues).
161
+ # '\e[1;%sr': Clearing the screen resets the scroll region(?). Re-set it.
162
+ # Also sets cursor to (0,0).
163
+ # ENV["TMUX:+\e[2J]"],
164
+ printf("\e[%sH\e[9999C\e[1J\e[1;%sr", \
165
+ $glines - 0, # was 2
166
+ $glines) # was grows
167
+ end
168
+
169
+ # copied from fff
170
+ # Call before shelling to editor pager and when exiting
171
+ def reset_terminal
172
+ # Reset the terminal to a useable state (undo all changes).
173
+ # '\e[?7h': Re-enable line wrapping.
174
+ # '\e[?25h': Unhide the cursor.
175
+ # '\e[2J': Clear the terminal.
176
+ # '\e[;r': Set the scroll region to its default value.
177
+ # Also sets cursor to (0,0).
178
+ print "\e[?7h\e[?25h\e[2J\e[;r"
179
+
180
+ # Show user input.
181
+ system 'stty echo'
182
+ end
183
+
184
+ # copied from fff
185
+ # call AFTER shelling to most or vim
186
+ def setup_terminal
187
+ # Setup the terminal for the TUI.
188
+ # '\e[?7l': Disable line wrapping.
189
+ # '\e[?25l': Hide the cursor.
190
+ # '\e[2J': Clear the screen.
191
+ # '\e[1;Nr': Limit scrolling to scrolling area.
192
+ # Also sets cursor to (0,0).
193
+ printf("\e[?7l\e[?25l\e[2J\e[1;%sr", $glines)
194
+ # earlier glines was grows
195
+
196
+ # Hide echoing of user input
197
+ system 'stty -echo'
198
+ end
199
+
136
200
  ## get a character from user and return as a string
137
201
  # Adapted from:
138
202
  #http://stackoverflow.com/questions/174933/how-to-get-a-single-character-without-pressing-enter/8274275#8274275
139
203
  # Need to take complex keys and matc against a hash.
140
204
  def get_char
141
205
  begin
142
- system("stty raw -echo 2>/dev/null") # turn raw input on
206
+ system('stty raw -echo 2>/dev/null') # turn raw input on
143
207
  c = nil
144
208
  #if $stdin.ready?
145
- c = $stdin.getc
146
- cn=c.ord
147
- return "ENTER" if cn == 10 || cn == 13
148
- return "BACKSPACE" if cn == 127
149
- return "C-SPACE" if cn == 0
150
- return "SPACE" if cn == 32
151
- # next does not seem to work, you need to bind C-i
152
- return "TAB" if cn == 8
153
- if cn >= 0 && cn < 27
154
- x= cn + 96
155
- return "C-#{x.chr}"
156
- end
157
- if c == ''
158
- buff=c.chr
159
- while true
160
- k = nil
161
- if $stdin.ready?
162
- k = $stdin.getc
163
- #puts "got #{k}"
164
- buff += k.chr
165
- else
166
- x=$kh[buff]
167
- return x if x
168
- #puts "returning with #{buff}"
169
- if buff.size == 2
170
- ## possibly a meta/alt char
171
- k = buff[-1]
172
- return "M-#{k.chr}"
173
- end
174
- return buff
209
+ c = $stdin.getc
210
+ cn = c.ord
211
+ return 'ENTER' if cn == 10 || cn == 13
212
+ return 'BACKSPACE' if cn == 127
213
+ return 'C-SPACE' if cn == 0
214
+ return 'SPACE' if cn == 32
215
+ # next does not seem to work, you need to bind C-i
216
+ return 'TAB' if cn == 8
217
+
218
+ if cn >= 0 && cn < 27
219
+ x = cn + 96
220
+ return "C-#{x.chr}"
221
+ end
222
+ if c == ''
223
+ buff=c.chr
224
+ while true
225
+ k = nil
226
+ if $stdin.ready?
227
+ k = $stdin.getc
228
+ #puts "got #{k}"
229
+ buff += k.chr
230
+ else
231
+ x = $kh[buff]
232
+ return x if x
233
+
234
+ # puts "returning with #{buff}"
235
+ if buff.size == 2
236
+ ## possibly a meta/alt char
237
+ k = buff[-1]
238
+ return "M-#{k.chr}"
175
239
  end
240
+ return buff
176
241
  end
177
242
  end
243
+ end
178
244
  #end
179
245
  return c.chr if c
180
246
  ensure
181
247
  #system "stty -raw echo" # turn raw input off
182
- system("stty -raw echo 2>/dev/null") # turn raw input on
248
+ system('stty -raw echo 2>/dev/null') # turn raw input on
183
249
  end
184
250
  end
185
251
 
@@ -187,6 +253,7 @@ end
187
253
  #$IDX="123456789abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
188
254
  #$IDX="abcdefghijklmnopqrstuvwxy"
189
255
  $IDX=('a'..'y').to_a
256
+ $IDX.delete 'q'
190
257
  $IDX.concat ('za'..'zz').to_a
191
258
  $IDX.concat ('Za'..'Zz').to_a
192
259
  $IDX.concat ('ZA'..'ZZ').to_a
@@ -247,14 +314,15 @@ $sta = $cursor = 0
247
314
  $visual_mode = false
248
315
  #$help = "#{BOLD}1-9a-zA-Z#{BOLD_OFF} Select #{BOLD}/#{BOLD_OFF} Grep #{BOLD}'#{BOLD_OFF} First char #{BOLD}M-n/p#{BOLD_OFF} Paging #{BOLD}!#{BOLD_OFF} Command Mode #{BOLD}@#{BOLD_OFF} Selection Mode #{BOLD}q#{BOLD_OFF} Quit"
249
316
 
250
- $help = "#{BOLD}M-?#{BOLD_OFF} Help #{BOLD}`#{BOLD_OFF} Menu #{BOLD}!#{BOLD_OFF} Command #{BOLD}=#{BOLD_OFF} Toggle #{BOLD}@#{BOLD_OFF} Selection Mode #{BOLD}Q#{BOLD_OFF} Quit "
317
+ $help = "#{BOLD}M-?#{BOLD_OFF} Help #{BOLD}`#{BOLD_OFF} Menu #{BOLD}!#{BOLD_OFF} Command #{BOLD}=#{BOLD_OFF} Toggle #{BOLD}@#{BOLD_OFF} Selection Mode #{BOLD}q#{BOLD_OFF} Quit "
251
318
 
252
319
  ## main loop which calls all other programs
253
- def run()
320
+ def run
254
321
  home=ENV['HOME']
255
322
  ctr=0
256
323
  config_read
257
324
  $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}M)'`.split("\n")
325
+ $files = sort_file_list $files
258
326
  enhance_file_list
259
327
  ## added by RK 2014-03-31 - 00:29 since too many duplicates
260
328
  $files = $files.uniq if $enhanced_mode
@@ -272,7 +340,7 @@ def run()
272
340
  else
273
341
  $view = $files.grep(/#{$patt}/)
274
342
  end
275
- else
343
+ else
276
344
  $view = $files
277
345
  end
278
346
  fl=$view.size
@@ -280,11 +348,11 @@ def run()
280
348
  $viewport = $view[$sta, $pagesize]
281
349
  fin = $sta + $viewport.size
282
350
  $title ||= Dir.pwd.sub(home, "~")
283
- system("clear")
351
+ clear_screen
284
352
  # title
285
353
  print "#{GREEN}#{$help} #{BLUE}cetus #{VERSION}#{CLEAR}\n"
286
354
  t = "#{$title} #{$sta + 1} to #{fin} of #{fl} #{$sorto} F:#{$filterstr}"
287
- t = t[t.size-$gcols..-1] if t.size >= $gcols
355
+ t = t[t.size - $gcols..-1] if t.size >= $gcols
288
356
  print "#{BOLD}#{t}#{CLEAR}\n"
289
357
  ## nilling the title means a superimposed one gets cleared.
290
358
  #$title = nil
@@ -304,7 +372,9 @@ def run()
304
372
  #puts
305
373
  #break if ch == "q"
306
374
  #elsif ch =~ /^[1-9a-zA-Z]$/
307
- if ch =~ /^[a-zZ]$/
375
+ # 2019-03-04 - ignore q since that is quit key now
376
+ #if ch =~ /^[a-zZ]$/
377
+ if ch =~ /^[a-pr-zZ]$/
308
378
  # hint mode
309
379
  select_hint $viewport, ch
310
380
  ctr = 0
@@ -328,7 +398,7 @@ def run()
328
398
  end
329
399
  break if $quitting
330
400
  end
331
- write_curdir
401
+ write_curdir
332
402
  puts "bye"
333
403
  config_write if $writing
334
404
  end
@@ -364,7 +434,7 @@ end
364
434
  def date_format t
365
435
  t.strftime "%Y/%m/%d"
366
436
  end
367
- ##
437
+ ##
368
438
  #
369
439
  # print in columns
370
440
  # ary - array of data
@@ -373,7 +443,7 @@ end
373
443
  def columnate ary, sz
374
444
  buff=Array.new
375
445
  return buff if ary.nil? || ary.size == 0
376
-
446
+
377
447
  # determine width based on number of files to show
378
448
  # if less than sz then 1 col and full width
379
449
  #
@@ -433,7 +503,7 @@ def columnate ary, sz
433
503
  end
434
504
  return buff
435
505
  end
436
- ## formats the data with number, mark and details
506
+ ## formats the data with number, mark and details
437
507
  def format ary
438
508
  #buff = Array.new
439
509
  buff = Array.new(ary.size)
@@ -513,6 +583,7 @@ def toggle_select f
513
583
  $selected_files.push f
514
584
  end
515
585
  end
586
+
516
587
  ## open file or directory
517
588
  def open_file f
518
589
  return unless f
@@ -520,7 +591,7 @@ def open_file f
520
591
  f = File.expand_path(f)
521
592
  end
522
593
  unless File.exist? f
523
- # this happens if we use (T) in place of (M)
594
+ # this happens if we use (T) in place of (M)
524
595
  # it places a space after normal files and @ and * which borks commands
525
596
  last = f[-1]
526
597
  if last == " " || last == "@" || last == '*'
@@ -555,7 +626,10 @@ def open_file f
555
626
  else
556
627
  comm = comm + " #{Shellwords.escape(f)}"
557
628
  end
629
+ clear_screen
630
+ reset_terminal
558
631
  system("#{comm}")
632
+ setup_terminal
559
633
  f = Dir.pwd + "/" + f if f[0] != '/'
560
634
  $visited_files.insert(0, f)
561
635
  push_used_dirs Dir.pwd
@@ -580,7 +654,7 @@ def run_command f
580
654
  end
581
655
  print "Run a command on #{files}: "
582
656
  begin
583
- #Readline::HISTORY.push(*values)
657
+ #Readline::HISTORY.push(*values)
584
658
  command = Readline::readline('>', true)
585
659
  #command = gets().chomp
586
660
  return if command.size == 0
@@ -604,12 +678,13 @@ def run_command f
604
678
  end
605
679
 
606
680
  ## cd to a dir
607
- def change_dir f, pos=nil
681
+ def change_dir f, pos = nil
608
682
  $visited_dirs.insert(0, Dir.pwd)
609
683
  f = File.expand_path(f)
610
684
  Dir.chdir f
611
685
  $filterstr ||= "M"
612
686
  $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
687
+ $files = sort_file_list $files
613
688
  post_cd
614
689
  if pos
615
690
  # convert curpos to sta also
@@ -634,10 +709,18 @@ end
634
709
  def refresh
635
710
  $filterstr ||= "M"
636
711
  $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
637
- $patt=nil
712
+ # first put dirs then files
713
+ $files = sort_file_list $files
714
+ $patt = nil
638
715
  $title = nil
639
716
  end
640
- #
717
+
718
+ def sort_file_list files
719
+ _dirs = $files.select { |f| File.directory?(f) }
720
+ _files = $files.select { |f| File.file?(f) }
721
+ return _dirs + _files
722
+ end
723
+
641
724
  ## unselect all files
642
725
  def unselect_all
643
726
  $selected_files = []
@@ -666,7 +749,7 @@ def goto_dir
666
749
  ## check for env variable
667
750
  tmp = ENV[path]
668
751
  if tmp.nil? || !File.directory?( tmp )
669
- ## check for dir in home
752
+ ## check for dir in home
670
753
  tmp = File.expand_path("~/#{path}")
671
754
  if File.directory? tmp
672
755
  f = tmp
@@ -704,7 +787,7 @@ def command_mode
704
787
  $mode = 'COM'
705
788
  end
706
789
  def goto_parent_dir
707
- change_dir ".."
790
+ change_dir '..'
708
791
  end
709
792
  ## This actually filters, in zfm it goes to that entry since we have a cursor there
710
793
  #
@@ -758,8 +841,9 @@ end
758
841
  def prev_page
759
842
  $sta -= $pagesize
760
843
  end
844
+
761
845
  def print_help
762
- system("clear")
846
+ clear_screen
763
847
  puts "HELP"
764
848
  puts
765
849
  puts "To open a file or dir press 1-9 a-z A-Z "
@@ -785,7 +869,7 @@ def show_marks
785
869
  end
786
870
  # MENU MAIN -- keep consistent with zfm
787
871
  def main_menu
788
- h = {
872
+ h = {
789
873
  :a => :ack,
790
874
  "/" => :ffind,
791
875
  :l => :locate,
@@ -795,7 +879,7 @@ def main_menu
795
879
  :r => :recent_files,
796
880
  :t => :dirtree,
797
881
  "4" => :tree,
798
- :s => :sort_menu,
882
+ :s => :sort_menu,
799
883
  :F => :filter_menu,
800
884
  :c => :command_menu ,
801
885
  :B => :bindkey_ext_command,
@@ -821,7 +905,7 @@ def menu title, h
821
905
  return ch, binding
822
906
  end
823
907
  def toggle_menu
824
- h = { :h => :toggle_hidden, :c => :toggle_case, :l => :toggle_long_list , "1" => :toggle_columns,
908
+ h = { :h => :toggle_hidden, :c => :toggle_case, :l => :toggle_long_list , "1" => :toggle_columns,
825
909
  :p => :toggle_pager_mode, :e => :toggle_enhanced_list}
826
910
  ch, menu_text = menu "Toggle Menu", h
827
911
  case menu_text
@@ -834,7 +918,7 @@ def toggle_menu
834
918
  refresh
835
919
  when :toggle_columns
836
920
  $gviscols = 3 if $gviscols == 1
837
- #$long_listing = false if $gviscols > 1
921
+ #$long_listing = false if $gviscols > 1
838
922
  x = $grows * $gviscols
839
923
  $pagesize = $pagesize==x ? $grows : x
840
924
  when :toggle_pager_mode
@@ -862,7 +946,7 @@ end
862
946
 
863
947
  def sort_menu
864
948
  lo = nil
865
- h = { :n => :newest, :a => :accessed, :o => :oldest,
949
+ h = { :n => :newest, :a => :accessed, :o => :oldest,
866
950
  :l => :largest, :s => :smallest , :m => :name , :r => :rname, :d => :dirs, :c => :clear }
867
951
  ch, menu_text = menu "Sort Menu", h
868
952
  case menu_text
@@ -893,7 +977,7 @@ def sort_menu
893
977
  end
894
978
 
895
979
  def command_menu
896
- ##
980
+ ##
897
981
  # since these involve full paths, we need more space, like only one column
898
982
  #
899
983
  ## in these cases, getting back to the earlier dir, back to earlier listing
@@ -903,7 +987,7 @@ def command_menu
903
987
  # xargs ls -t etc rather than the zsh sort order. But we can run a filter using |.
904
988
  #
905
989
  h = { :t => :today, :D => :default_command , :R => :remove_from_list}
906
- if $editor_mode
990
+ if $editor_mode
907
991
  h[:e] = :pager_mode
908
992
  else
909
993
  h[:e] = :editor_mode
@@ -1010,8 +1094,11 @@ def pop_dir
1010
1094
  Dir.chdir d
1011
1095
  $filterstr ||= "M"
1012
1096
  $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
1097
+ $files = sort_file_list $files
1013
1098
  post_cd
1014
1099
  end
1100
+
1101
+ # after changing directory
1015
1102
  def post_cd
1016
1103
  $patt=nil
1017
1104
  $sta = $cursor = 0
@@ -1026,10 +1113,9 @@ def post_cd
1026
1113
  enhance_file_list
1027
1114
  ## added by RK 2014-03-31 - 00:29 since too many duplicates
1028
1115
  $files = $files.uniq if $enhanced_mode
1029
-
1030
1116
  revert_dir_pos
1031
1117
  end
1032
- #
1118
+
1033
1119
  ## read dirs and files and bookmarks from file
1034
1120
  def config_read
1035
1121
  #f = File.expand_path("~/.zfminfo")
@@ -1070,11 +1156,11 @@ def config_write
1070
1156
  f1 = File.expand_path(CONFIG_FILE)
1071
1157
  d = $used_dirs.join ":"
1072
1158
  f = $visited_files.join ":"
1073
- File.open(f1, 'w+') do |f2|
1074
- # use "\n" for two lines of text
1159
+ File.open(f1, 'w+') do |f2|
1160
+ # use "\n" for two lines of text
1075
1161
  f2.puts "DIRS=\"#{d}\""
1076
1162
  f2.puts "FILES=\"#{f}\""
1077
- $bookmarks.each_pair { |k, val|
1163
+ $bookmarks.each_pair { |k, val|
1078
1164
  f2.puts "BM_#{k}=\"#{val}\""
1079
1165
  #f2.puts "BOOKMARKS[\"#{k}\"]=\"#{val}\""
1080
1166
  }
@@ -1125,20 +1211,20 @@ def subcommand
1125
1211
  $quitting = true
1126
1212
  $writing = true if $modified
1127
1213
  elsif command == "p"
1128
- system "echo $PWD | pbcopy"
1129
- puts "Stored PWD in clipboard (using pbcopy)"
1214
+ system 'echo $PWD | pbcopy'
1215
+ puts 'Stored PWD in clipboard (using pbcopy)'
1130
1216
  end
1131
1217
  end
1132
1218
  def quit_command
1133
1219
  if $modified
1134
- puts "Press w to save bookmarks before quitting " if $modified
1135
- print "Press another q to quit "
1220
+ puts 'Press w to save bookmarks before quitting ' if $modified
1221
+ print 'Press another q to quit '
1136
1222
  ch = get_char
1137
1223
  else
1138
1224
  $quitting = true
1139
1225
  end
1140
- $quitting = true if ch == "q"
1141
- $quitting = $writing = true if ch == "w"
1226
+ $quitting = true if ch == 'q'
1227
+ $quitting = $writing = true if ch == 'w'
1142
1228
  end
1143
1229
 
1144
1230
  def views
@@ -1175,6 +1261,7 @@ def recent_files
1175
1261
  $title = "Recent files"
1176
1262
  $files = `zsh -c 'print -rl -- **/*(Dom[1,15])'`.split("\n")
1177
1263
  end
1264
+
1178
1265
  def select_current
1179
1266
  ## vp is local there, so i can do $vp[0]
1180
1267
  #open_file $view[$sta] if $view[$sta]
@@ -1262,7 +1349,7 @@ end
1262
1349
  def ask_hint deflt=nil
1263
1350
  f = nil
1264
1351
  ch = get_char
1265
- if ch == "ENTER"
1352
+ if ch == "ENTER"
1266
1353
  return deflt
1267
1354
  end
1268
1355
  ix = get_index(ch, $viewport.size)
@@ -1273,16 +1360,17 @@ end
1273
1360
  ## check screen size and accordingly adjust some variables
1274
1361
  #
1275
1362
  def screen_settings
1276
- $glines=%x(tput lines).to_i
1277
- $gcols=%x(tput cols).to_i
1363
+ $glines = %x(tput lines).to_i
1364
+ $gcols = %x(tput cols).to_i
1278
1365
  $grows = $glines - 3
1279
1366
  $pagesize = 60
1280
1367
  #$gviscols = 3
1281
1368
  $pagesize = $grows * $gviscols
1282
1369
  end
1370
+
1283
1371
  ## moves column offset so we can reach unindexed columns or entries
1284
1372
  # 0 forward and any other back/prev
1285
- def column_next dir=0
1373
+ def column_next dir = 0
1286
1374
  if dir == 0
1287
1375
  $stact += $grows
1288
1376
  $stact = 0 if $stact >= $viewport.size
@@ -1291,9 +1379,10 @@ def column_next dir=0
1291
1379
  $stact = 0 if $stact < 0
1292
1380
  end
1293
1381
  end
1382
+
1294
1383
  # currently i am only passing the action in from the list there as a key
1295
1384
  # I should be able to pass in new actions that are external commands
1296
- def file_actions action=nil
1385
+ def file_actions(action=nil)
1297
1386
  h = { :d => :delete, :m => :move, :r => :rename, :v => ENV["EDITOR"] || :vim,
1298
1387
  :c => :copy, :C => :chdir,
1299
1388
  :l => :less, :s => :most , :f => :file , :o => :open, :x => :dtrx, :z => :zip }
@@ -1326,7 +1415,7 @@ def file_actions action=nil
1326
1415
  menu_text = action
1327
1416
  else
1328
1417
  ch, menu_text = menu "File Menu for #{text}", h
1329
- menu_text = :quit if ch == "q"
1418
+ menu_text = :quit if ch == 'q'
1330
1419
  end
1331
1420
  case menu_text.to_sym
1332
1421
  when :quit
@@ -1403,7 +1492,7 @@ end
1403
1492
 
1404
1493
  # bind a key to an external command wich can be then be used for files
1405
1494
  def bindkey_ext_command
1406
- print
1495
+ print
1407
1496
  pbold "Bind a capital letter to an external command"
1408
1497
  print "Enter a capital letter to bind: "
1409
1498
  ch = get_char
@@ -1484,7 +1573,7 @@ def z_interface
1484
1573
  $title = "Directories from ~/.z"
1485
1574
  $files = `sort -rn -k2 -t '|' ~/.z | cut -f1 -d '|'`.split("\n")
1486
1575
  home = ENV['HOME']
1487
- $files.collect! do |f|
1576
+ $files.collect! do |f|
1488
1577
  f.sub(/#{home}/,"~")
1489
1578
  end
1490
1579
  end
@@ -1525,7 +1614,7 @@ def moveto pos
1525
1614
  if $visual_mode
1526
1615
  # PWD has to be there in selction
1527
1616
  if $selected_files.index $view[$cursor]
1528
- # this depends on the direction
1617
+ # this depends on the direction
1529
1618
  $selected_files = $selected_files - $view[star..fin]
1530
1619
  ## current row remains in selection always.
1531
1620
  $selected_files.push $view[$cursor]
@@ -1541,6 +1630,7 @@ def visual_mode_toggle
1541
1630
  $selected_files.push $view[$cursor]
1542
1631
  end
1543
1632
  end
1633
+
1544
1634
  def visual_block_clear
1545
1635
  if $visual_block_start
1546
1636
  star = [$visual_block_start, $cursor].min
@@ -1550,6 +1640,7 @@ def visual_block_clear
1550
1640
  $visual_block_start = nil
1551
1641
  $visual_mode = nil
1552
1642
  end
1643
+
1553
1644
  def file_starting_with fc
1554
1645
  ix = return_next_match(method(:file_matching?), "^#{fc}")
1555
1646
  if ix
@@ -1567,7 +1658,7 @@ def return_next_match binding, *args
1567
1658
  $view.each_with_index do |elem,ii|
1568
1659
  if binding.call(elem, *args)
1569
1660
  first ||= ii
1570
- if ii > $cursor
1661
+ if ii > $cursor
1571
1662
  ix = ii
1572
1663
  break
1573
1664
  end
@@ -1603,7 +1694,7 @@ def filetype f
1603
1694
  nil
1604
1695
  end
1605
1696
 
1606
- def save_dir_pos
1697
+ def save_dir_pos
1607
1698
  return if $sta == 0 && $cursor == 0
1608
1699
  $dir_position[Dir.pwd] = [$sta, $cursor]
1609
1700
  end
@@ -1619,7 +1710,7 @@ def revert_dir_pos
1619
1710
  end
1620
1711
  end
1621
1712
  def newdir
1622
- print
1713
+ print
1623
1714
  print "Enter directory name: "
1624
1715
  str = Readline::readline('>', true)
1625
1716
  return if str == ""
@@ -1636,7 +1727,7 @@ def newdir
1636
1727
  end
1637
1728
  end
1638
1729
  def newfile
1639
- print
1730
+ print
1640
1731
  print "Enter file name: "
1641
1732
  str = Readline::readline('>', true)
1642
1733
  return if str == ""
@@ -1646,7 +1737,7 @@ def newfile
1646
1737
  end
1647
1738
 
1648
1739
  ##
1649
- # Editing of the User Dir List.
1740
+ # Editing of the User Dir List.
1650
1741
  # remove current entry from used dirs list, since we may not want some entries being there
1651
1742
  #
1652
1743
  def remove_from_list
@@ -1686,7 +1777,7 @@ def enhance_file_list
1686
1777
  return unless $enhanced_mode
1687
1778
  # if only one entry and its a dir
1688
1779
  # get its children and maybe the recent mod files a few
1689
-
1780
+
1690
1781
  if $files.size == 1
1691
1782
  # its a dir, let give the next level at least
1692
1783
  if $files.first[-1] == "/"
@@ -1702,7 +1793,7 @@ def enhance_file_list
1702
1793
  return
1703
1794
  end
1704
1795
  end
1705
- #
1796
+ #
1706
1797
  # check if a ruby project dir, although it could be a backup file too,
1707
1798
  # if so , expand lib and maby bin, put a couple recent files
1708
1799
  #
@@ -1767,7 +1858,7 @@ def insert_into_list dir, file
1767
1858
  #raise "something wrong can find #{dir}." unless ix
1768
1859
  #$files.insert ix, *file
1769
1860
  # 2013-03-19 - 19:42 adding at end to avoid confusion
1770
- #$files.concat file
1861
+ #$files.concat file
1771
1862
  $files.push *file
1772
1863
  end
1773
1864
  def get_important_files dir
@@ -1789,4 +1880,11 @@ def get_important_files dir
1789
1880
  return list
1790
1881
  end
1791
1882
 
1792
- run
1883
+ Signal.trap('EXIT') {
1884
+ reset_terminal
1885
+ # system 'tput rmcup'
1886
+ exit
1887
+ }
1888
+ run
1889
+ # 2019-02-20 - added so alt-screen is used
1890
+ system 'tput rmcup'
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cetus"
8
- spec.version = "0.1.18"
8
+ spec.version = "0.1.21"
9
9
  spec.authors = ["Rahul Kumar"]
10
10
  spec.email = ["oneness.univ@gmail.com"]
11
11
  spec.description = %q{lightning fast file navigator}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cetus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahul Kumar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-19 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubyforge_project:
76
- rubygems_version: 2.5.2.3
75
+ rubygems_version: 3.0.2
77
76
  signing_key:
78
77
  specification_version: 4
79
78
  summary: lightning fast file navigator - ruby 1.9.3 .. ruby 2.5