cetus 0.1.28 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cetus +387 -247
- data/cetus.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6bfd0c8210eacca8888f7c6f22e5682feff8c82f3a90d799849d8bb153fd5e9
|
4
|
+
data.tar.gz: 3ebbdd0708cd4cc6f75a3a77a2161f443a68d703f2c769ca870ffd37242f839e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0425f755732c290eaf51aa0903a6785fef35f54d72b83f2fd281280e5c00064706cad9dd2d598419a1495d9625792a0b3e15dcb7e0edb1fc8c5f07d177fcc2a
|
7
|
+
data.tar.gz: 5d9c5f24e835a522adccfc91156469ff148b66013c49ac1c83fc5d41fd00da212500eb2786765593a0585baf4210c9a75f614914b34e1d2faa9ffca5ac7f2613
|
data/bin/cetus
CHANGED
@@ -6,7 +6,7 @@
|
|
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-03-
|
9
|
+
# Last update: 2019-03-24 11:58
|
10
10
|
# --------------------------------------------------------------------------- #
|
11
11
|
# cetus.rb Copyright (C) 2012-2019 rahul kumar
|
12
12
|
# == CHANGELOG
|
@@ -15,7 +15,10 @@
|
|
15
15
|
# 2019-03-04 - changed quit to q (earlier Q)
|
16
16
|
# 2019-03-04 - first dirs then files
|
17
17
|
# 2019-03-10 - changing selected_files to have fullpath
|
18
|
+
# 2019-03-22 - refactoring the code, esp run()
|
18
19
|
# == TODO
|
20
|
+
# FIXME how to check that redraw not called twice depending on where
|
21
|
+
# a method is called from. a menu or direct from key. e.g help
|
19
22
|
# To dirs add GEMHOME RUBYLIB PYTHONILB or PYTHONPATH,
|
20
23
|
# Make rubygem aware : gemspec or Gemfile the expand lib and bin
|
21
24
|
# fpath if existing
|
@@ -32,9 +35,7 @@ require 'fileutils'
|
|
32
35
|
# alias c=~/bin/cetus.rb
|
33
36
|
# c
|
34
37
|
|
35
|
-
|
36
|
-
system 'tput smcup'
|
37
|
-
VERSION = '0.1.28.0'.freeze
|
38
|
+
VERSION = '0.1.29.0'.freeze
|
38
39
|
CONFIG_FILE = '~/.config/cetus/conf.yml'.freeze
|
39
40
|
|
40
41
|
$bindings = {}
|
@@ -175,7 +176,8 @@ def reset_terminal
|
|
175
176
|
# '\e[2J': Clear the terminal.
|
176
177
|
# '\e[;r': Set the scroll region to its default value.
|
177
178
|
# Also sets cursor to (0,0).
|
178
|
-
|
179
|
+
# '\e[?1049l: Restore main screen buffer.
|
180
|
+
print "\e[?7h\e[?25h\e[2J\e[;r\e[?1049l"
|
179
181
|
|
180
182
|
# Show user input.
|
181
183
|
system 'stty echo'
|
@@ -185,12 +187,13 @@ end
|
|
185
187
|
# call AFTER shelling to most or vim
|
186
188
|
def setup_terminal
|
187
189
|
# Setup the terminal for the TUI.
|
190
|
+
# '\e[?1049h': Use alternative screen buffer. smcup
|
188
191
|
# '\e[?7l': Disable line wrapping.
|
189
192
|
# '\e[?25l': Hide the cursor.
|
190
193
|
# '\e[2J': Clear the screen.
|
191
194
|
# '\e[1;Nr': Limit scrolling to scrolling area.
|
192
195
|
# Also sets cursor to (0,0).
|
193
|
-
printf("\e[?7l\e[?25l\e[2J\e[1;%sr", $glines)
|
196
|
+
printf("\e[?1049h\e[?7l\e[?25l\e[2J\e[1;%sr", $glines)
|
194
197
|
# earlier glines was grows
|
195
198
|
|
196
199
|
# Hide echoing of user input
|
@@ -209,7 +212,7 @@ def readline prompt='>'
|
|
209
212
|
# hide cursor
|
210
213
|
print "\e[?25l"
|
211
214
|
end
|
212
|
-
target
|
215
|
+
target.chomp
|
213
216
|
end
|
214
217
|
|
215
218
|
## get a character from user and return as a string
|
@@ -331,148 +334,168 @@ $status_color = 4 # status line, can be 2 3 4 5 6
|
|
331
334
|
# Menubar on top of screen
|
332
335
|
@help = "#{BOLD}?#{BOLD_OFF} Help #{BOLD}`#{BOLD_OFF} Menu #{BOLD}!#{BOLD_OFF} Execute #{BOLD}=#{BOLD_OFF} Toggle #{BOLD}C-x#{BOLD_OFF} File Actions #{BOLD}q#{BOLD_OFF} Quit "
|
333
336
|
|
334
|
-
|
335
|
-
def
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}
|
337
|
+
# ------------------- read_directory ------------------ #
|
338
|
+
def read_directory
|
339
|
+
rescan_required false
|
340
|
+
# $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}M)'`.split("\n")
|
341
|
+
$filterstr ||= 'M'
|
342
|
+
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
|
340
343
|
$files = sort_file_list $files
|
341
344
|
enhance_file_list
|
342
345
|
## added by RK 2014-03-31 - 00:29 since too many duplicates
|
343
346
|
$files = $files.uniq if $enhanced_mode
|
347
|
+
end
|
348
|
+
# ------------- end of read_directory --------------------------------#
|
344
349
|
|
345
|
-
|
346
|
-
|
347
|
-
$
|
348
|
-
|
349
|
-
|
350
|
-
# forever loop that prints dir and takes a key
|
351
|
-
loop do
|
352
|
-
|
353
|
-
# view consists of all files (filtered by pattern if necessary)
|
354
|
-
$view = if $patt
|
355
|
-
if $ignorecase
|
356
|
-
$files.grep(/#{$patt}/i)
|
357
|
-
else
|
358
|
-
$files.grep(/#{$patt}/)
|
359
|
-
end
|
350
|
+
# ------------------- create_viewport ------------------ #
|
351
|
+
def create_viewport
|
352
|
+
$view = if $patt
|
353
|
+
if $ignorecase
|
354
|
+
$files.grep(/#{$patt}/i)
|
360
355
|
else
|
361
|
-
$files
|
356
|
+
$files.grep(/#{$patt}/)
|
362
357
|
end
|
358
|
+
else
|
359
|
+
$files
|
360
|
+
end
|
363
361
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
$cursor = 0 if $cursor >= fl || $cursor < 0
|
368
|
-
|
369
|
-
# NOTE if we make cursor zero, then it can be < sta so in the next line
|
370
|
-
# it will be made equal to sta which we may not want
|
371
|
-
# $sta = $cursor if $sta > $cursor
|
372
|
-
$cursor = $sta if $sta > $cursor
|
373
|
-
|
374
|
-
# viewport are the files that are visible, subset of view
|
375
|
-
$viewport = $view[$sta, $pagesize]
|
376
|
-
fin = $sta + $viewport.size
|
377
|
-
|
378
|
-
# added 2019-03-20 - actually stact should be reduced not brought to zero
|
379
|
-
# 2019-03-21 - NOTE this may be redundant since I set to zero in next_page
|
380
|
-
# due to various edge cases.
|
381
|
-
# $stact = 0 if $stact >= $viewport.size
|
382
|
-
if $stact >= $viewport.size
|
383
|
-
$stact -= $grows while $stact >= $viewport.size
|
384
|
-
$stact += $grows if $stact < 0
|
385
|
-
end
|
362
|
+
fl = $view.size
|
363
|
+
$sta = 0 if $sta >= fl || $sta < 0
|
364
|
+
$cursor = 0 if $cursor >= fl || $cursor < 0
|
386
365
|
|
387
|
-
|
388
|
-
|
366
|
+
# NOTE if we make cursor zero, then it can be < sta so in the next line
|
367
|
+
# it will be made equal to sta which we may not want
|
368
|
+
$cursor = $sta if $sta > $cursor
|
389
369
|
|
370
|
+
# viewport are the files that are visible, subset of view
|
371
|
+
$viewport = $view[$sta, $pagesize]
|
372
|
+
end
|
373
|
+
# ------------- end of create_viewport --------------------------------#
|
390
374
|
|
391
|
-
|
392
|
-
|
393
|
-
t = "#{$title} #{$sta + 1} to #{fin} of #{fl} #{$sorto} F:#{$filterstr}"
|
394
|
-
t = t[t.size - $gcols..-1] if t.size >= $gcols
|
395
|
-
print "#{BOLD}#{t}#{CLEAR}\n"
|
375
|
+
# ------------------- print_title ------------------ #
|
376
|
+
def print_title
|
396
377
|
|
397
|
-
|
398
|
-
|
378
|
+
# print help line and version
|
379
|
+
print "#{GREEN}#{@help} #{BLUE}cetus #{VERSION}#{CLEAR}\n"
|
399
380
|
|
400
|
-
|
401
|
-
|
381
|
+
# print 1 of n files, sort order, filter etc details
|
382
|
+
$title ||= Dir.pwd.sub(ENV['HOME'], '~')
|
383
|
+
fin = $sta + $viewport.size
|
384
|
+
fl = $view.size
|
385
|
+
t = "#{$title} #{$sta + 1} to #{fin} of #{fl} #{$sorto} F:#{$filterstr}"
|
402
386
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
387
|
+
# don't exceed columns while printing
|
388
|
+
t = t[t.size - $gcols..-1] if t.size >= $gcols
|
389
|
+
|
390
|
+
print "#{BOLD}#{t}#{CLEAR}\n"
|
391
|
+
end
|
392
|
+
# ------------- end of print_title --------------------------------#
|
407
393
|
|
394
|
+
# TODO clean this up and simplify it
|
395
|
+
def status_line
|
408
396
|
# prompt
|
409
397
|
v_mm = $mode ? "[#{$mode}] " : ''
|
410
398
|
cf = current_file
|
411
399
|
$message = "No file highlighted (#{cf})" if cf and !$highlighted_a_column
|
412
400
|
$message = ' | No matches. Press ESCAPE' if $patt && !cf
|
413
|
-
# 2019-03-19 - take cursor to last line
|
414
|
-
system "tput cup #{$glines} 0"
|
415
401
|
|
416
|
-
|
417
|
-
# \e[33;41m - set color of status_line
|
418
|
-
# %*s - set blank spaces for entire line
|
419
|
-
print "\e[33;4%sm%*s" % [$status_color || '1', $gcols, " "]
|
402
|
+
clear_status_line
|
420
403
|
|
421
404
|
# Print the filename at the right side of the status_line
|
422
405
|
# sometimes due to search, there is no file
|
423
406
|
if cf
|
424
|
-
cfl = cf.size
|
425
|
-
# print right aligned
|
426
|
-
padding = @debug_flag ? 15 : 3
|
427
|
-
system "tput cup #{$glines} #{$gcols - cfl - padding}"
|
407
|
+
# cfl = cf.size
|
408
|
+
# print right aligned TODO REFACTOR THIS
|
409
|
+
# padding = @debug_flag ? 15 : 3
|
410
|
+
# system "tput cup #{$glines} #{$gcols - cfl - padding}"
|
428
411
|
# print "#{REVERSE}#{cf}#{CLEAR}"
|
429
412
|
if @debug_flag
|
430
|
-
|
413
|
+
print_on_right "#{$sta},#{$cursor},#{$stact},#{$viewport.size},#{$grows} | #{cf}"
|
431
414
|
else
|
432
|
-
|
415
|
+
print_on_right "#{cf}"
|
433
416
|
end
|
434
417
|
end
|
435
418
|
# print "\r#{v_mm}#{$patt} #{GREEN}#{$message}#{CLEAR} >"
|
436
419
|
# move to beginning of line, reset text mode after printing
|
437
420
|
print "\r#{v_mm}#{$patt}#{$message}\e[m"
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
421
|
+
|
422
|
+
end
|
423
|
+
|
424
|
+
# should we do a read of the dir
|
425
|
+
def rescan?
|
426
|
+
$rescan_required
|
427
|
+
end
|
428
|
+
|
429
|
+
def rescan_required flag=true
|
430
|
+
$rescan_required = flag
|
431
|
+
redraw_required if flag
|
432
|
+
end
|
433
|
+
|
434
|
+
def redraw flag=false
|
435
|
+
read_directory if flag
|
436
|
+
|
437
|
+
draw_directory
|
438
|
+
end
|
439
|
+
|
440
|
+
def draw_directory
|
441
|
+
# all this seems to be happening for each keystroke even if
|
442
|
+
# not really required. FIXME maybe reduce and call when required
|
443
|
+
|
444
|
+
|
445
|
+
# view consists of all files (filtered by pattern if necessary)
|
446
|
+
# viewport is only that subset of view that is displayed on screen
|
447
|
+
create_viewport
|
448
|
+
clear_screen
|
449
|
+
print_title
|
450
|
+
|
451
|
+
# add hint and format the line
|
452
|
+
buff = _format $viewport
|
453
|
+
|
454
|
+
# break into as many columns as required
|
455
|
+
# This is where directories get their blue color
|
456
|
+
buff = columnate buff, $grows
|
457
|
+
|
458
|
+
buff.each { |line| print line, "\n" }
|
459
|
+
print
|
460
|
+
|
461
|
+
status_line
|
462
|
+
end
|
463
|
+
|
464
|
+
def redraw_required(flag=true) $redraw_required = flag; end
|
465
|
+
|
466
|
+
def resolve_key key
|
467
|
+
if key.match?(/^[a-pr-zZ]$/)
|
468
|
+
# hint mode
|
469
|
+
select_hint $viewport, key
|
470
|
+
elsif key == 'BACKSPACE'
|
471
|
+
# do we really need this TODO
|
472
|
+
$patt = $patt[0..-2] if $patt && !$patt.empty?
|
473
|
+
$message = $patt = nil if $patt == ''
|
474
|
+
else
|
475
|
+
resolve_binding key
|
470
476
|
end
|
471
|
-
write_curdir
|
472
|
-
puts 'bye'
|
473
|
-
config_write if $writing
|
474
477
|
end
|
475
478
|
|
479
|
+
def resolve_binding key
|
480
|
+
# fetch binding for key
|
481
|
+
x = $bindings[key]
|
482
|
+
|
483
|
+
# remove comment string so only binding is left
|
484
|
+
x, _ = x.split(':') if x
|
485
|
+
|
486
|
+
# split into binding and args
|
487
|
+
x = x.split if x
|
488
|
+
if x
|
489
|
+
binding = x.shift
|
490
|
+
args = x
|
491
|
+
send(binding, *args) if binding
|
492
|
+
else
|
493
|
+
perror "No binding for #{key}"
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
|
498
|
+
|
476
499
|
## write current dir to a file so we can ccd to it when exiting
|
477
500
|
def write_curdir
|
478
501
|
f = File.expand_path('~/.fff_d')
|
@@ -603,6 +626,9 @@ end
|
|
603
626
|
# method and this overshadowed that method.
|
604
627
|
# NOTE: this does not do any coloring since the codes may get chopped by
|
605
628
|
# columnate method
|
629
|
+
# TODO 2019-03-23 - 23:30 we can do coloring here. columnate must check for color
|
630
|
+
# code at start of line, and check size accordingly. If it needs to truncate, then
|
631
|
+
# first take off the ANSI codes, truncate and put back.
|
606
632
|
def _format(ary)
|
607
633
|
# buff = Array.new
|
608
634
|
buff = Array.new(ary.size)
|
@@ -611,15 +637,19 @@ def _format(ary)
|
|
611
637
|
# determine width based on number of files to show
|
612
638
|
# if less than sz then 1 col and full width
|
613
639
|
#
|
614
|
-
# ix refers to the index in the complete file list,
|
640
|
+
# ix refers to the index in the complete file list, whereas we only
|
641
|
+
# show 60 at a time
|
615
642
|
ix = 0
|
616
643
|
ctr = 0
|
617
644
|
ary.each do |f|
|
645
|
+
# raise "#{f} != #{ary[ix]}" if f != ary[ix]
|
618
646
|
## ctr refers to the index in the column
|
619
647
|
ind = get_shortcut(ix)
|
620
648
|
mark = SPACE
|
649
|
+
mark = '+' if visited? f
|
621
650
|
cur = SPACE
|
622
651
|
cur = CURMARK if ix + $sta == $cursor
|
652
|
+
# NOTE seems like f and ary[ix] are the same
|
623
653
|
mark = GMARK if selected?(ary[ix])
|
624
654
|
|
625
655
|
if $long_listing
|
@@ -659,11 +689,11 @@ def _format(ary)
|
|
659
689
|
end
|
660
690
|
|
661
691
|
## select file based on key pressed
|
662
|
-
def select_hint
|
692
|
+
def select_hint view, key
|
663
693
|
# a to y is direct
|
664
694
|
# if x or z take a key IF there are those many
|
665
695
|
#
|
666
|
-
ix = get_index(
|
696
|
+
ix = get_index(key, view.size)
|
667
697
|
return unless ix
|
668
698
|
|
669
699
|
f = view[ix]
|
@@ -678,7 +708,6 @@ def select_hint(view, ch)
|
|
678
708
|
else
|
679
709
|
open_file f
|
680
710
|
end
|
681
|
-
# selectedix=ix
|
682
711
|
end
|
683
712
|
|
684
713
|
## toggle selection state of file
|
@@ -690,6 +719,8 @@ def toggle_select(f=current_file)
|
|
690
719
|
else
|
691
720
|
add_to_selection f
|
692
721
|
end
|
722
|
+
# XXX is it possible to just redraw this line
|
723
|
+
redraw_required
|
693
724
|
end
|
694
725
|
|
695
726
|
## open file or directory
|
@@ -711,6 +742,7 @@ def open_file(f)
|
|
711
742
|
save_dir_pos
|
712
743
|
change_dir f, nextpos
|
713
744
|
elsif File.readable? f
|
745
|
+
# TODO: looks complex pls simplify !! XXX
|
714
746
|
$default_command ||= '$PAGER'
|
715
747
|
if !$editor_mode
|
716
748
|
ft = filetype f
|
@@ -740,6 +772,7 @@ def open_file(f)
|
|
740
772
|
perror "open_file: (#{f}) not found"
|
741
773
|
# could check home dir or CDPATH env variable DO
|
742
774
|
end
|
775
|
+
redraw_required
|
743
776
|
end
|
744
777
|
|
745
778
|
# regardless of mode, view the current file using pager
|
@@ -808,25 +841,35 @@ def run_command(f)
|
|
808
841
|
get_char
|
809
842
|
end
|
810
843
|
|
811
|
-
## cd to a dir
|
812
|
-
|
844
|
+
## cd to a dir.
|
845
|
+
# Also, position cursor on child directory that we changed from if second param
|
846
|
+
# is true.
|
847
|
+
def change_dir f, position_cursor=false
|
813
848
|
unless File.directory? f
|
814
|
-
perror "#{
|
849
|
+
perror "#{f} is not a directory, or does not exist."
|
815
850
|
return
|
816
851
|
end
|
817
|
-
|
818
|
-
|
852
|
+
|
853
|
+
# before leaving a dir we save it in the list, as well as the cursor
|
854
|
+
# position, so we can restore that position when we return
|
855
|
+
dir_from = Dir.pwd
|
856
|
+
$visited_dirs.insert(0, dir_from)
|
857
|
+
save_dir_pos
|
858
|
+
|
819
859
|
f = File.expand_path(f)
|
820
860
|
Dir.chdir f
|
821
|
-
|
822
|
-
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
|
823
|
-
$files = sort_file_list $files
|
861
|
+
read_directory
|
824
862
|
post_cd
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
863
|
+
|
864
|
+
# position the cursor on the previous directory
|
865
|
+
# This happens when we go to parent directory
|
866
|
+
if position_cursor
|
867
|
+
# get the position of the previous directory
|
868
|
+
pos = index_of(File.basename(dir_from) + '/')
|
869
|
+
$cursor = pos if pos
|
829
870
|
end
|
871
|
+
|
872
|
+
redraw_required
|
830
873
|
end
|
831
874
|
|
832
875
|
def goto_previous_dir
|
@@ -835,6 +878,10 @@ def goto_previous_dir
|
|
835
878
|
change_dir prev_dir
|
836
879
|
end
|
837
880
|
|
881
|
+
def index_of dir
|
882
|
+
$files.index(dir)
|
883
|
+
end
|
884
|
+
|
838
885
|
## clear sort order and refresh listing, used typically if you are in some view
|
839
886
|
# such as visited dirs or files
|
840
887
|
def escape
|
@@ -850,12 +897,9 @@ end
|
|
850
897
|
|
851
898
|
## refresh listing after some change like option change, or toggle
|
852
899
|
def refresh
|
853
|
-
$filterstr ||= 'M'
|
854
|
-
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
|
855
|
-
# first put dirs then files
|
856
|
-
$files = sort_file_list $files
|
857
900
|
$patt = nil
|
858
901
|
$title = nil
|
902
|
+
rescan_required
|
859
903
|
end
|
860
904
|
|
861
905
|
# put directories first, then files
|
@@ -879,18 +923,22 @@ end
|
|
879
923
|
|
880
924
|
## accept dir to goto and change to that ( can be a file too)
|
881
925
|
def goto_dir
|
882
|
-
print "\e[?25h"
|
883
|
-
|
926
|
+
# print "\e[?25h"
|
927
|
+
print_last_line 'Enter path: '
|
884
928
|
begin
|
885
929
|
# path = gets.chomp
|
886
930
|
path = readline
|
887
|
-
|
931
|
+
if path.nil? || path == ''
|
932
|
+
clear_status_line
|
933
|
+
return
|
934
|
+
end
|
888
935
|
# rescue => ex
|
889
936
|
rescue StandardError => ex
|
937
|
+
# Nope, already caught interrupt and sent back nil
|
890
938
|
perror 'Cancelled cd, press a key'
|
891
939
|
return
|
892
940
|
ensure
|
893
|
-
print "\e[?25l"
|
941
|
+
# print "\e[?25l"
|
894
942
|
end
|
895
943
|
f = File.expand_path(path)
|
896
944
|
unless File.directory? f
|
@@ -939,14 +987,17 @@ end
|
|
939
987
|
def goto_parent_dir
|
940
988
|
# 2019-03-20 - when changing to parent, we need to keep cursor on
|
941
989
|
# parent dir, not first
|
942
|
-
curr = File.basename(Dir.pwd)
|
990
|
+
# curr = File.basename(Dir.pwd)
|
943
991
|
|
944
|
-
change_dir '..'
|
992
|
+
change_dir '..', true
|
945
993
|
|
994
|
+
# TODO 2019-03-24 - we can revert to old thing and remove second arg from cd
|
995
|
+
# FIXME 2019-03-23 - too late to change the cursor here since change_dir
|
996
|
+
# now does a redraw !!! XXX
|
946
997
|
# get index of child dir in this dir, and set cursor to it.
|
947
|
-
index = $files.index(curr + '/')
|
948
|
-
pause "WARNING: Could not find #{curr} in this directory." unless index
|
949
|
-
$cursor = index if index
|
998
|
+
# index = $files.index(curr + '/')
|
999
|
+
# pause "WARNING: Could not find #{curr} in this directory." unless index
|
1000
|
+
# $cursor = index if index
|
950
1001
|
end
|
951
1002
|
|
952
1003
|
def goto_home_dir
|
@@ -969,13 +1020,13 @@ end
|
|
969
1020
|
|
970
1021
|
# Goes to directory bookmarked with number or upper case char.
|
971
1022
|
# If lower case character given, then go to first file starting with char.
|
972
|
-
def goto_bookmark(
|
973
|
-
unless
|
1023
|
+
def goto_bookmark(key = nil)
|
1024
|
+
unless key
|
974
1025
|
print 'Enter bookmark char: '
|
975
|
-
|
1026
|
+
key = get_char
|
976
1027
|
end
|
977
|
-
if
|
978
|
-
d = $bookmarks[
|
1028
|
+
if key =~ /^[0-9A-Z]$/
|
1029
|
+
d = $bookmarks[key]
|
979
1030
|
# this is if we use zfm's bookmarks which have a position
|
980
1031
|
# this way we leave the position as is, so it gets written back
|
981
1032
|
nextpos = nil
|
@@ -987,11 +1038,11 @@ def goto_bookmark(ch = nil)
|
|
987
1038
|
end
|
988
1039
|
change_dir d, nextpos
|
989
1040
|
else
|
990
|
-
perror "#{
|
1041
|
+
perror "#{key} not a bookmark"
|
991
1042
|
end
|
992
1043
|
else
|
993
|
-
# goto_entry_starting_with
|
994
|
-
file_starting_with
|
1044
|
+
# goto_entry_starting_with key
|
1045
|
+
file_starting_with key
|
995
1046
|
end
|
996
1047
|
end
|
997
1048
|
|
@@ -1013,6 +1064,7 @@ def next_page
|
|
1013
1064
|
# FIXME: 2019-03-20 - if cursor is panned to 3rd column and then we page,
|
1014
1065
|
# then after a while no hints show up since stact is high.
|
1015
1066
|
$stact = 0
|
1067
|
+
redraw_required
|
1016
1068
|
# next just does not work on the last page when it should
|
1017
1069
|
# perhaps viewport has not yet been adjusted, that's why
|
1018
1070
|
# $stact = 0 if $stact >= $viewport.size
|
@@ -1024,6 +1076,7 @@ end
|
|
1024
1076
|
def prev_page
|
1025
1077
|
$sta -= $pagesize
|
1026
1078
|
$cursor -= $pagesize
|
1079
|
+
redraw_required
|
1027
1080
|
end
|
1028
1081
|
|
1029
1082
|
def print_help
|
@@ -1090,6 +1143,7 @@ def debug_vars
|
|
1090
1143
|
file.puts "grows #{$grows}"
|
1091
1144
|
file.puts "file #{current_file}"
|
1092
1145
|
end
|
1146
|
+
redraw_required
|
1093
1147
|
end
|
1094
1148
|
|
1095
1149
|
def view_bookmarks
|
@@ -1098,8 +1152,8 @@ def view_bookmarks
|
|
1098
1152
|
$bookmarks.each_pair { |k, v| puts "#{k.ljust(7)} => #{v}" }
|
1099
1153
|
puts
|
1100
1154
|
print 'Enter bookmark to goto: '
|
1101
|
-
|
1102
|
-
goto_bookmark(
|
1155
|
+
key = get_char
|
1156
|
+
goto_bookmark(key) if key =~ /^[0-9A-Z]$/
|
1103
1157
|
end
|
1104
1158
|
|
1105
1159
|
# MENU MAIN -- keep consistent with zfm
|
@@ -1153,7 +1207,7 @@ def bookmark_menu
|
|
1153
1207
|
end
|
1154
1208
|
|
1155
1209
|
# Create a menu using title, and hash of key and binding
|
1156
|
-
def menu
|
1210
|
+
def menu title, h
|
1157
1211
|
return unless h
|
1158
1212
|
|
1159
1213
|
pbold title.to_s
|
@@ -1164,15 +1218,16 @@ def menu(title, h)
|
|
1164
1218
|
x = ary.join("\n")
|
1165
1219
|
puts %x{echo "#{x}" | column}
|
1166
1220
|
|
1167
|
-
|
1168
|
-
binding = h[
|
1169
|
-
binding ||= h[
|
1221
|
+
key = get_char
|
1222
|
+
binding = h[key]
|
1223
|
+
binding ||= h[key.to_sym]
|
1170
1224
|
# TODO: 2019-03-21 - menu's do not have comments, they are symbols
|
1171
1225
|
# binding, _ = binding.split(':')
|
1172
1226
|
if binding
|
1173
1227
|
send(binding) if respond_to?(binding, true)
|
1174
1228
|
end
|
1175
|
-
|
1229
|
+
redraw_required
|
1230
|
+
[key, binding]
|
1176
1231
|
end
|
1177
1232
|
|
1178
1233
|
def toggle_menu
|
@@ -1184,15 +1239,15 @@ def toggle_menu
|
|
1184
1239
|
case menu_text
|
1185
1240
|
when :toggle_hidden
|
1186
1241
|
$hidden = $hidden ? nil : 'D'
|
1187
|
-
pause "Show hidden files is now #{!$hidden.nil?}"
|
1242
|
+
# pause "Show hidden files is now #{!$hidden.nil?}. Press a key."
|
1188
1243
|
message "Show hidden is now #{!$hidden.nil?}"
|
1189
|
-
|
1244
|
+
rescan_required
|
1190
1245
|
when :toggle_case
|
1191
1246
|
# $ignorecase = $ignorecase ? "" : "i"
|
1192
1247
|
$ignorecase = !$ignorecase
|
1193
|
-
pause "Ignore Case is now #{$ignorecase}"
|
1248
|
+
# pause "Ignore Case is now #{$ignorecase}. Press a key."
|
1194
1249
|
message "Ignore Case is now #{$ignorecase}"
|
1195
|
-
|
1250
|
+
rescan_required
|
1196
1251
|
when :toggle_columns
|
1197
1252
|
# FIXME: 2019-03-20 - if 3 then 1
|
1198
1253
|
# adjust stact and sta, if moving from panned position
|
@@ -1205,6 +1260,7 @@ def toggle_menu
|
|
1205
1260
|
x = $grows * $gviscols
|
1206
1261
|
$pagesize = $pagesize == x ? $grows : x
|
1207
1262
|
message "Visible columns now set to #{$gviscols}"
|
1263
|
+
rescan_required
|
1208
1264
|
when :toggle_pager_mode
|
1209
1265
|
$editor_mode = !$editor_mode
|
1210
1266
|
$default_command = if $editor_mode
|
@@ -1217,6 +1273,7 @@ def toggle_menu
|
|
1217
1273
|
when :toggle_enhanced_list
|
1218
1274
|
$enhanced_mode = !$enhanced_mode
|
1219
1275
|
message "Enhanced mode is #{$long_listing}"
|
1276
|
+
rescan_required
|
1220
1277
|
|
1221
1278
|
when :toggle_long_list
|
1222
1279
|
$long_listing = !$long_listing
|
@@ -1235,7 +1292,7 @@ def toggle_menu
|
|
1235
1292
|
$stact = 0 # in case user was panned 2019-03-20 -
|
1236
1293
|
end
|
1237
1294
|
message "Long listing is #{$long_listing}, vis cols is #{$gviscols}"
|
1238
|
-
|
1295
|
+
rescan_required
|
1239
1296
|
end
|
1240
1297
|
end
|
1241
1298
|
|
@@ -1243,7 +1300,7 @@ def sort_menu
|
|
1243
1300
|
lo = nil
|
1244
1301
|
h = { m: :modified, a: :accessed, M: :oldest,
|
1245
1302
|
l: :largest, s: :smallest, n: :name, r: :rev_name, d: :dirs, c: :clear }
|
1246
|
-
|
1303
|
+
_, menu_text = menu 'Sort Menu', h
|
1247
1304
|
case menu_text
|
1248
1305
|
when :modified
|
1249
1306
|
lo = 'om'
|
@@ -1266,8 +1323,10 @@ def sort_menu
|
|
1266
1323
|
end
|
1267
1324
|
## This needs to persist and be a part of all listings, put in change_dir.
|
1268
1325
|
$sorto = lo
|
1269
|
-
|
1270
|
-
|
1326
|
+
message "Sorted on #{menu_text}"
|
1327
|
+
rescan_required
|
1328
|
+
# $files = `zsh -c 'print -rl -- *(#{lo}#{$hidden}M)'`.split("\n") if lo
|
1329
|
+
# $title = nil
|
1271
1330
|
# $files =$(eval "print -rl -- ${pattern}(${MFM_LISTORDER}$filterstr)")
|
1272
1331
|
end
|
1273
1332
|
|
@@ -1300,6 +1359,7 @@ def command_menu
|
|
1300
1359
|
when :locate
|
1301
1360
|
locate
|
1302
1361
|
when :today
|
1362
|
+
# FIXME use filterstring
|
1303
1363
|
$files = `zsh -c 'print -rl -- *(#{$hidden}Mm0)'`.split("\n")
|
1304
1364
|
$title = "Today's files"
|
1305
1365
|
when :default_command
|
@@ -1316,12 +1376,13 @@ def command_menu
|
|
1316
1376
|
$default_command = nil
|
1317
1377
|
end
|
1318
1378
|
end
|
1379
|
+
# redraw
|
1319
1380
|
end
|
1320
1381
|
|
1321
1382
|
# This is quite badly placed and named. Maybe these should go elsewhere
|
1322
1383
|
def extras
|
1323
1384
|
h = { '1' => :one_column, '2' => :multi_column, :c => :columns, :r => :config_read, :w => :config_write }
|
1324
|
-
|
1385
|
+
key, menu_text = menu 'Extras Menu', h
|
1325
1386
|
case menu_text
|
1326
1387
|
when :one_column
|
1327
1388
|
$pagesize = $grows
|
@@ -1330,10 +1391,10 @@ def extras
|
|
1330
1391
|
$pagesize = $grows * $gviscols
|
1331
1392
|
when :columns
|
1332
1393
|
print "How many columns to show: 1-6 [current #{$gviscols}]? "
|
1333
|
-
|
1334
|
-
|
1335
|
-
if
|
1336
|
-
$gviscols =
|
1394
|
+
key = get_char
|
1395
|
+
key = key.to_i
|
1396
|
+
if key > 0 && key < 7
|
1397
|
+
$gviscols = key.to_i
|
1337
1398
|
$pagesize = $grows * $gviscols
|
1338
1399
|
end
|
1339
1400
|
end
|
@@ -1342,7 +1403,7 @@ end
|
|
1342
1403
|
def filter_menu
|
1343
1404
|
h = { :d => :dirs, :f => :files, :e => :emptydirs, '0' => :emptyfiles,
|
1344
1405
|
:r => :reduce_list, :x => :extension}
|
1345
|
-
|
1406
|
+
_, menu_text = menu 'Filter Menu', h
|
1346
1407
|
files = nil
|
1347
1408
|
case menu_text
|
1348
1409
|
when :dirs
|
@@ -1369,6 +1430,8 @@ def filter_menu
|
|
1369
1430
|
if files
|
1370
1431
|
$files = files
|
1371
1432
|
$stact = 0
|
1433
|
+
$message = "Filtered on #{menu_text}"
|
1434
|
+
# redraw
|
1372
1435
|
end
|
1373
1436
|
end
|
1374
1437
|
|
@@ -1391,6 +1454,7 @@ def select_from_used_dirs
|
|
1391
1454
|
$title = 'Used Directories'
|
1392
1455
|
home = File.expand_path '~'
|
1393
1456
|
$files = $used_dirs.uniq.map { |path| path.sub("#{home}", '~') }
|
1457
|
+
# redraw
|
1394
1458
|
end
|
1395
1459
|
|
1396
1460
|
def select_from_visited_files
|
@@ -1398,6 +1462,7 @@ def select_from_visited_files
|
|
1398
1462
|
$title = 'Visited Files'
|
1399
1463
|
home = File.expand_path '~'
|
1400
1464
|
$files = $visited_files.uniq.map { |path| path.sub("#{home}", '~') }
|
1465
|
+
# redraw
|
1401
1466
|
end
|
1402
1467
|
|
1403
1468
|
# maybe unused ??? XXX
|
@@ -1416,32 +1481,28 @@ def pop_dir
|
|
1416
1481
|
## XXX make sure the dir exists, cuold have been deleted. can be an error or crash otherwise
|
1417
1482
|
$visited_dirs.push d
|
1418
1483
|
Dir.chdir d
|
1419
|
-
$filterstr ||= 'M'
|
1420
|
-
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
|
1421
|
-
$files = sort_file_list $files
|
1484
|
+
# $filterstr ||= 'M'
|
1485
|
+
# $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n")
|
1486
|
+
# $files = sort_file_list $files
|
1422
1487
|
post_cd
|
1488
|
+
rescan_required
|
1423
1489
|
end
|
1424
1490
|
|
1425
1491
|
# after changing directory
|
1426
1492
|
def post_cd
|
1427
|
-
$patt = nil
|
1428
|
-
$sta = $cursor = 0
|
1429
|
-
$title = nil
|
1430
|
-
$message = nil
|
1493
|
+
$title = $patt = $message = nil
|
1494
|
+
$sta = $cursor = $stact = 0
|
1431
1495
|
$visual_block_start = nil
|
1432
|
-
$stact = 0
|
1433
1496
|
$current_dir = Dir.pwd # 2019-03-10 - so i don't keep doing in functions
|
1434
1497
|
screen_settings
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
$files = $files.uniq if $enhanced_mode
|
1498
|
+
|
1499
|
+
# goto last position cursor was in this dir
|
1500
|
+
# THis only makes sense if called after read_directory but before redraw
|
1439
1501
|
revert_dir_pos
|
1440
1502
|
end
|
1441
1503
|
|
1442
1504
|
## read dirs and files and bookmarks from file
|
1443
1505
|
def config_read
|
1444
|
-
# f = File.expand_path("~/.zfminfo")
|
1445
1506
|
f = File.expand_path(CONFIG_FILE)
|
1446
1507
|
return unless File.readable? f
|
1447
1508
|
|
@@ -1499,16 +1560,20 @@ end
|
|
1499
1560
|
|
1500
1561
|
## accept a character to save this dir as a bookmark
|
1501
1562
|
def create_bookmark
|
1563
|
+
|
1502
1564
|
print 'Enter A to Z or 0-9 to create a bookmark: '
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1565
|
+
print "\e[?25h" # unhide cursor
|
1566
|
+
key = get_char
|
1567
|
+
print "\e[?25l" # hide cursor
|
1568
|
+
if key =~ /^[0-9A-Z]$/
|
1569
|
+
# $bookmarks[key] = "#{Dir.pwd}:#{$cursor}"
|
1570
|
+
$bookmarks[key] = Dir.pwd
|
1507
1571
|
$modified = true
|
1508
|
-
message "Created bookmark #{
|
1572
|
+
message "Created bookmark #{key}"
|
1509
1573
|
else
|
1510
1574
|
perror 'Bookmark must be upper-case character or number.'
|
1511
1575
|
end
|
1576
|
+
# redraw
|
1512
1577
|
end
|
1513
1578
|
|
1514
1579
|
# allow user to exit using :q :wq :x
|
@@ -1519,17 +1584,18 @@ def subcommand
|
|
1519
1584
|
begin
|
1520
1585
|
command = readline
|
1521
1586
|
return if command == ''
|
1522
|
-
rescue StandardError
|
1587
|
+
rescue StandardError
|
1523
1588
|
return
|
1524
1589
|
end
|
1525
1590
|
if command == 'q'
|
1591
|
+
# FIXME: 2019-03-22 - should this not call quit_command ?
|
1526
1592
|
if $modified
|
1527
1593
|
print 'Do you want to save bookmarks? (y/n): '
|
1528
|
-
|
1529
|
-
if
|
1594
|
+
key = get_char
|
1595
|
+
if key == 'y'
|
1530
1596
|
$writing = true
|
1531
1597
|
$quitting = true
|
1532
|
-
elsif
|
1598
|
+
elsif key == 'n'
|
1533
1599
|
$quitting = true
|
1534
1600
|
print 'Quitting without saving bookmarks'
|
1535
1601
|
else
|
@@ -1556,18 +1622,19 @@ def subcommand
|
|
1556
1622
|
else
|
1557
1623
|
perror "Don't know about command #{command}. Try :h or :help"
|
1558
1624
|
end
|
1625
|
+
# redraw
|
1559
1626
|
end
|
1560
1627
|
|
1561
1628
|
def quit_command
|
1562
1629
|
if $modified
|
1563
1630
|
puts 'Press w to save bookmarks before quitting ' if $modified
|
1564
1631
|
print 'Press another q to quit '
|
1565
|
-
|
1632
|
+
key = get_char
|
1566
1633
|
else
|
1567
1634
|
$quitting = true
|
1568
1635
|
end
|
1569
|
-
$quitting = true if
|
1570
|
-
$quitting = $writing = true if
|
1636
|
+
$quitting = true if key == 'q'
|
1637
|
+
$quitting = $writing = true if key == 'w'
|
1571
1638
|
end
|
1572
1639
|
|
1573
1640
|
def views
|
@@ -1579,16 +1646,21 @@ def views
|
|
1579
1646
|
$viewctr = 0 if $viewctr > views.size
|
1580
1647
|
|
1581
1648
|
$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}M)'`.split("\n")
|
1649
|
+
# redraw
|
1582
1650
|
end
|
1583
1651
|
|
1584
1652
|
def child_dirs
|
1585
|
-
$title = '
|
1653
|
+
$title = 'Directories in current directory'
|
1586
1654
|
$files = `zsh -c 'print -rl -- *(/#{$sorto}#{$hidden}M)'`.split("\n")
|
1655
|
+
message "#{$files.size} files."
|
1656
|
+
# redraw
|
1587
1657
|
end
|
1588
1658
|
|
1589
1659
|
def dirtree
|
1590
|
-
$title = 'Child directories'
|
1660
|
+
$title = 'Child directories with depth'
|
1591
1661
|
$files = `zsh -c 'print -rl -- **/*(/#{$sorto}#{$hidden}M)'`.split("\n")
|
1662
|
+
message "#{$files.size} files."
|
1663
|
+
# redraw
|
1592
1664
|
end
|
1593
1665
|
|
1594
1666
|
#
|
@@ -1598,6 +1670,8 @@ def tree
|
|
1598
1670
|
# Caution: use only for small projects, don't use in root.
|
1599
1671
|
$title = 'Full Tree'
|
1600
1672
|
$files = `zsh -c 'print -rl -- **/*(#{$sorto}#{$hidden}M)'`.split("\n")
|
1673
|
+
message "#{$files.size} files."
|
1674
|
+
# redraw
|
1601
1675
|
end
|
1602
1676
|
|
1603
1677
|
# lists recent files in current dir
|
@@ -1606,6 +1680,7 @@ def recent_files
|
|
1606
1680
|
# print -rl -- **/*(Dom[1,10])
|
1607
1681
|
$title = 'Recent files'
|
1608
1682
|
$files = `zsh -c 'print -rl -- **/*(Dom[1,15])'`.split("\n").reject {|f| f[0] == '.'}
|
1683
|
+
# redraw
|
1609
1684
|
end
|
1610
1685
|
|
1611
1686
|
def select_current
|
@@ -1622,16 +1697,20 @@ def push_used_dirs(d = Dir.pwd)
|
|
1622
1697
|
$used_dirs.insert(0, d)
|
1623
1698
|
end
|
1624
1699
|
|
1625
|
-
def pbold
|
1700
|
+
def pbold text
|
1626
1701
|
puts "#{BOLD}#{text}#{BOLD_OFF}"
|
1627
1702
|
end
|
1628
1703
|
|
1629
|
-
|
1630
|
-
|
1704
|
+
# This is supposed to print on the status line
|
1705
|
+
# but prints on next line.FIXME 2019-03-24 - 00:08
|
1706
|
+
def perror text
|
1707
|
+
clear_status_line
|
1708
|
+
last_line
|
1709
|
+
print "#{RED}#{text}. Press a key.#{CLEAR}"
|
1631
1710
|
get_char
|
1632
1711
|
end
|
1633
1712
|
|
1634
|
-
def pause
|
1713
|
+
def pause text=' Press a key.'
|
1635
1714
|
print text
|
1636
1715
|
get_char
|
1637
1716
|
end
|
@@ -1707,10 +1786,10 @@ end
|
|
1707
1786
|
#
|
1708
1787
|
def ask_hint(deflt = nil)
|
1709
1788
|
f = nil
|
1710
|
-
|
1711
|
-
return deflt if
|
1789
|
+
key = get_char
|
1790
|
+
return deflt if key == 'ENTER'
|
1712
1791
|
|
1713
|
-
ix = get_index(
|
1792
|
+
ix = get_index(key, $viewport.size)
|
1714
1793
|
f = $viewport[ix] if ix
|
1715
1794
|
f
|
1716
1795
|
end
|
@@ -1726,11 +1805,12 @@ def screen_settings
|
|
1726
1805
|
$pagesize = $grows * $gviscols
|
1727
1806
|
end
|
1728
1807
|
|
1729
|
-
##
|
1808
|
+
## Tabs to next column in multi-column displays.
|
1809
|
+
# Moves column offset so we can reach unindexed columns or entries,
|
1810
|
+
# or those with double letters
|
1730
1811
|
# 0 forward and any other back/prev
|
1731
|
-
# direction is 0 (forward) or 1 (backward)
|
1732
|
-
|
1733
|
-
def column_next(direction = 0)
|
1812
|
+
# direction is 0 (forward) or '1' (backward)
|
1813
|
+
def column_next direction=0
|
1734
1814
|
# right movement or panning cycles back to first column
|
1735
1815
|
# leftward movement stops at first column.
|
1736
1816
|
if direction == 0
|
@@ -1753,6 +1833,7 @@ def column_next(direction = 0)
|
|
1753
1833
|
# We are trying to maintain offset
|
1754
1834
|
$cursor += $grows if $cursor < 0
|
1755
1835
|
end
|
1836
|
+
# redraw
|
1756
1837
|
end
|
1757
1838
|
|
1758
1839
|
# currently i am only passing the action in from the list there as a key
|
@@ -1796,12 +1877,12 @@ def file_actions(action = nil)
|
|
1796
1877
|
files = Shellwords.escape(file)
|
1797
1878
|
end
|
1798
1879
|
|
1799
|
-
|
1880
|
+
key = nil
|
1800
1881
|
if action
|
1801
1882
|
menu_text = action
|
1802
1883
|
else
|
1803
|
-
|
1804
|
-
menu_text = :quit if
|
1884
|
+
key, menu_text = menu "File Menu for #{text}", h
|
1885
|
+
menu_text = :quit if key == 'q'
|
1805
1886
|
end
|
1806
1887
|
return unless menu_text # pressed some wrong key
|
1807
1888
|
|
@@ -1812,9 +1893,9 @@ def file_actions(action = nil)
|
|
1812
1893
|
when :delete
|
1813
1894
|
delcommand = 'rmtrash'
|
1814
1895
|
print "#{delcommand} #{text} ?[yn?]: "
|
1815
|
-
|
1816
|
-
view_selected_files if
|
1817
|
-
return if
|
1896
|
+
key = get_char
|
1897
|
+
view_selected_files if key == '?'
|
1898
|
+
return if key != 'y'
|
1818
1899
|
|
1819
1900
|
system "#{delcommand} #{files}"
|
1820
1901
|
refresh
|
@@ -1969,11 +2050,11 @@ def bindkey_ext_command
|
|
1969
2050
|
print
|
1970
2051
|
pbold 'Bind a capital letter to an external command'
|
1971
2052
|
print 'Enter a capital letter to bind: '
|
1972
|
-
|
1973
|
-
return if
|
2053
|
+
key = get_char
|
2054
|
+
return if key == 'Q'
|
1974
2055
|
|
1975
|
-
if
|
1976
|
-
print "Enter an external command to bind to #{
|
2056
|
+
if key =~ /^[A-Z]$/
|
2057
|
+
print "Enter an external command to bind to #{key}: "
|
1977
2058
|
com = gets.chomp
|
1978
2059
|
if com != ''
|
1979
2060
|
print 'Enter prompt for command (blank if same as command): '
|
@@ -1982,7 +2063,7 @@ def bindkey_ext_command
|
|
1982
2063
|
end
|
1983
2064
|
print 'Pause after output [y/n]: '
|
1984
2065
|
yn = get_char
|
1985
|
-
$bindings[
|
2066
|
+
$bindings[key] = "command_file #{pro} #{yn} #{com}"
|
1986
2067
|
end
|
1987
2068
|
end
|
1988
2069
|
|
@@ -2009,6 +2090,7 @@ def ag
|
|
2009
2090
|
return
|
2010
2091
|
end
|
2011
2092
|
$files = files
|
2093
|
+
# redraw
|
2012
2094
|
end
|
2013
2095
|
|
2014
2096
|
def ffind
|
@@ -2023,6 +2105,7 @@ def ffind
|
|
2023
2105
|
else
|
2024
2106
|
$files = files
|
2025
2107
|
end
|
2108
|
+
# redraw
|
2026
2109
|
end
|
2027
2110
|
|
2028
2111
|
def locate
|
@@ -2038,6 +2121,7 @@ def locate
|
|
2038
2121
|
else
|
2039
2122
|
$files = files
|
2040
2123
|
end
|
2124
|
+
# redraw
|
2041
2125
|
end
|
2042
2126
|
|
2043
2127
|
## Displays files from .viminfo file, if you use some other editor which
|
@@ -2051,6 +2135,7 @@ def viminfo
|
|
2051
2135
|
# $files = `grep '^>' ~/.viminfo | cut -d ' ' -f 2- | sed "s#~#$HOME#g"`.split("\n")
|
2052
2136
|
$files = `grep '^>' ~/.viminfo | cut -d ' ' -f 2- `.split("\n")
|
2053
2137
|
$files.select! { |x| x = File.expand_path(x); File.exist?(x) }
|
2138
|
+
# redraw
|
2054
2139
|
end
|
2055
2140
|
|
2056
2141
|
## takes directories from the z program, if you use autojump you can
|
@@ -2066,35 +2151,27 @@ def z_interface
|
|
2066
2151
|
$files.collect! do |f|
|
2067
2152
|
f.sub(/#{home}/, '~')
|
2068
2153
|
end
|
2154
|
+
# redraw
|
2069
2155
|
end
|
2070
2156
|
|
2071
2157
|
def vidir
|
2072
2158
|
system 'vidir'
|
2073
2159
|
setup_terminal
|
2074
2160
|
end
|
2075
|
-
## there is no one consisten way i am getting.
|
2076
|
-
# i need to do a shell join if I am to pipe ffiles to say: xargs ls -t
|
2077
|
-
# but if i want to pipe names to grep xxx then i need to join with newlines
|
2078
|
-
# def pipe; end
|
2079
2161
|
|
2080
2162
|
## some cursor movement functions
|
2081
|
-
# TODO: 2019-03-18 - cursor should also be updated
|
2082
|
-
# sta is not updated when cursor > viewport.size and sta is still 0
|
2083
2163
|
def cursor_scroll_dn
|
2084
2164
|
moveto(pos + MSCROLL)
|
2085
2165
|
end
|
2086
2166
|
|
2087
|
-
# TODO: 2019-03-18 - cursor should also be updated
|
2088
2167
|
def cursor_scroll_up
|
2089
2168
|
moveto(pos - MSCROLL)
|
2090
2169
|
end
|
2091
2170
|
|
2092
|
-
# TODO: 2019-03-18 - cursor and sta should also be updated if page changes
|
2093
2171
|
def cursor_dn
|
2094
2172
|
moveto(pos + 1)
|
2095
2173
|
end
|
2096
2174
|
|
2097
|
-
# TODO: 2019-03-18 - cursor and sta should also be updated if page changes
|
2098
2175
|
def cursor_up
|
2099
2176
|
moveto(pos - 1)
|
2100
2177
|
end
|
@@ -2104,7 +2181,6 @@ def pos
|
|
2104
2181
|
end
|
2105
2182
|
|
2106
2183
|
# move cursor to given position/line
|
2107
|
-
# $sta should also move
|
2108
2184
|
def moveto(position)
|
2109
2185
|
orig = $cursor
|
2110
2186
|
$cursor = position
|
@@ -2139,6 +2215,8 @@ def moveto(position)
|
|
2139
2215
|
# $selected_files.concat $view[star..fin]
|
2140
2216
|
add_to_selection $view[star..fin]
|
2141
2217
|
end
|
2218
|
+
ensure
|
2219
|
+
# redraw
|
2142
2220
|
end
|
2143
2221
|
|
2144
2222
|
# is given file in selected array
|
@@ -2148,6 +2226,13 @@ def selected?(file)
|
|
2148
2226
|
return $selected_files.index file
|
2149
2227
|
end
|
2150
2228
|
|
2229
|
+
# is given file in selected array
|
2230
|
+
def visited?(file)
|
2231
|
+
$current_dir ||= Dir.pwd
|
2232
|
+
file = File.join($current_dir, file)
|
2233
|
+
return $visited_files.index file
|
2234
|
+
end
|
2235
|
+
|
2151
2236
|
# TODO: can be array
|
2152
2237
|
def add_to_selection(file)
|
2153
2238
|
ff = file
|
@@ -2366,8 +2451,8 @@ def remove_from_list
|
|
2366
2451
|
unless $selected_files.empty?
|
2367
2452
|
sz = $selected_files.size
|
2368
2453
|
print "Remove #{sz} files from used list (y)?: "
|
2369
|
-
|
2370
|
-
return if
|
2454
|
+
key = get_char
|
2455
|
+
return if key != 'y'
|
2371
2456
|
|
2372
2457
|
arr = $selected_files.map { |path| File.expand_path(path) }
|
2373
2458
|
|
@@ -2378,12 +2463,14 @@ def remove_from_list
|
|
2378
2463
|
refresh
|
2379
2464
|
return
|
2380
2465
|
end
|
2466
|
+
|
2467
|
+
# no file selected, use file under cursor
|
2381
2468
|
print
|
2382
2469
|
## what if selected some rows
|
2383
2470
|
file = $view[$cursor]
|
2384
2471
|
print "Remove #{file} from used list (y)?: "
|
2385
|
-
|
2386
|
-
return if
|
2472
|
+
key = get_char
|
2473
|
+
return if key != 'y'
|
2387
2474
|
|
2388
2475
|
file = File.expand_path(file)
|
2389
2476
|
if File.directory? file
|
@@ -2489,20 +2576,26 @@ def insert_into_list(_dir, file)
|
|
2489
2576
|
$files.push(*file)
|
2490
2577
|
end
|
2491
2578
|
|
2492
|
-
|
2579
|
+
# 2019-03-23 - not exactly clear what is happening XXX
|
2580
|
+
# this gets a directory (containing '/' at end)
|
2581
|
+
def get_important_files dir
|
2493
2582
|
# checks various lists like visited_files and bookmarks
|
2494
2583
|
# to see if files from this dir or below are in it.
|
2495
2584
|
# More to be used in a dir with few files.
|
2496
2585
|
list = []
|
2497
2586
|
l = dir.size + 1
|
2587
|
+
# 2019-03-23 - i think we are getting the basename of the file
|
2588
|
+
# if it is present in the given directory XXX
|
2498
2589
|
$visited_files.each do |e|
|
2499
2590
|
list << e[l..-1] if e.index(dir) == 0
|
2500
2591
|
end
|
2501
|
-
# bookmarks
|
2502
|
-
#
|
2503
|
-
#
|
2504
|
-
|
2505
|
-
|
2592
|
+
# bookmarks if it starts with this directory then add it
|
2593
|
+
# FIXME it puts same directory cetus into the list with full path
|
2594
|
+
# We need to remove the base until this dir. get relative part
|
2595
|
+
list1 = $bookmarks.values.select do |e|
|
2596
|
+
e.index(dir) == 0 && e != dir
|
2597
|
+
end
|
2598
|
+
list.concat list1
|
2506
2599
|
list
|
2507
2600
|
end
|
2508
2601
|
|
@@ -2511,13 +2604,60 @@ def message mess
|
|
2511
2604
|
$message = mess
|
2512
2605
|
end
|
2513
2606
|
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
2607
|
+
def last_line
|
2608
|
+
system "tput cup #{$glines} 0"
|
2609
|
+
end
|
2610
|
+
|
2611
|
+
def clear_status_line
|
2612
|
+
last_line
|
2613
|
+
# print a colored line at bottom of screen
|
2614
|
+
# \e[33;41m - set color of status_line
|
2615
|
+
# %*s - set blank spaces for entire line
|
2616
|
+
print "\e[33;4%sm%*s" % [$status_color || '1', $gcols, " "]
|
2617
|
+
end
|
2618
|
+
def print_on_right text
|
2619
|
+
sz = text.size
|
2620
|
+
system "tput cup #{$glines} #{$gcols - sz -1}"
|
2621
|
+
print text
|
2622
|
+
end
|
2623
|
+
|
2624
|
+
def print_last_line text
|
2625
|
+
last_line
|
2626
|
+
print text
|
2627
|
+
end
|
2628
|
+
|
2629
|
+
# main loop which calls all other programs
|
2630
|
+
def run
|
2631
|
+
|
2632
|
+
Signal.trap('EXIT') do
|
2633
|
+
reset_terminal
|
2634
|
+
exit
|
2635
|
+
end
|
2636
|
+
|
2637
|
+
setup_terminal
|
2638
|
+
config_read
|
2639
|
+
|
2640
|
+
redraw true
|
2641
|
+
|
2642
|
+
# do we need this, have they changed after redraw
|
2643
|
+
$patt = nil
|
2644
|
+
$sta = 0
|
2645
|
+
|
2646
|
+
# forever loop that prints dir and takes a key
|
2647
|
+
loop do
|
2648
|
+
|
2649
|
+
# moved the printing out of here
|
2650
|
+
# TODO we need to call it from where required
|
2651
|
+
|
2652
|
+
key = get_char
|
2653
|
+
resolve_key key
|
2654
|
+
redraw rescan?
|
2655
|
+
|
2656
|
+
break if $quitting
|
2657
|
+
end
|
2658
|
+
write_curdir
|
2659
|
+
puts 'bye'
|
2660
|
+
config_write if $writing
|
2518
2661
|
end
|
2519
2662
|
|
2520
|
-
setup_terminal
|
2521
2663
|
run
|
2522
|
-
# 2019-02-20 - added so alt-screen is used
|
2523
|
-
system 'tput rmcup'
|
data/cetus.gemspec
CHANGED
@@ -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.
|
8
|
+
spec.version = '0.1.29'
|
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.
|
4
|
+
version: 0.1.29
|
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-03-
|
11
|
+
date: 2019-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|