cetus 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cetus +127 -30
  3. data/cetus.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b9d18e0f61df366b1977e94b4492e2d5d89db8459082859c96325bb30459cc4
4
- data.tar.gz: 698d7c3e64d40e533d3fe1d028e2e2425d2fcd4db09cebb5803d9d64450009d5
3
+ metadata.gz: fe8c1244b0c3e4c41eb6f186f13a2145330c3243de099db9a91bac5a87f0b1c6
4
+ data.tar.gz: e732da1943a5b7ab651c736a6d56bd645ce9d58b9dbf1857efcb97713563c2e1
5
5
  SHA512:
6
- metadata.gz: 55a5c875ecf98f26123a9d3f7dac5e8cdc8731fede1c3767cad9f84a117827473ccb598f2ca5fc96f2e839a5bdfd2a50ce739a16c65f4aa1205afb20d0bfa053
7
- data.tar.gz: c444a54d8675e4c7d6953f3da43e07d1ac8f464b4f6cd835ec5e51da625e0e9ee55067ddb6fb00d8ed4cc78583515db23fca11c9b35bfe2d49eb10c2e16f3642
6
+ metadata.gz: 16cab047cb3fa5b2a9de8b25a8c3fe450ef9527896b19af2b5cd9d6ff5b554381c8b012dd21b2f9477ff8f00e080b3cf25d359e5c85103c3a777faa0ae1c171c
7
+ data.tar.gz: 106ccedd0121858ddd1a867a9d2c875c8ab9fd1b6cba34062fbeed6ec256c80032f23b9363ea78c018ab861d8eb189c91bde3b373d1963ea16b656a1c0e40597
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-16 10:17
9
+ # Last update: 2019-03-18 14:02
10
10
  # --------------------------------------------------------------------------- #
11
11
  # cetus.rb Copyright (C) 2012-2019 rahul kumar
12
12
  # == CHANGELOG
@@ -35,7 +35,7 @@ require 'fileutils'
35
35
 
36
36
  # 2019-02-20 - added so alt-screen is used
37
37
  system 'tput smcup'
38
- VERSION = '0.1.23.0'.freeze
38
+ VERSION = '0.1.24.0'.freeze
39
39
  O_CONFIG = true
40
40
  # CONFIG_FILE = '~/.lyrainfo'.freeze
41
41
  CONFIG_FILE = '~/.config/cetus/conf.yml'.freeze
@@ -45,11 +45,13 @@ $bindings = {
45
45
  '`' => 'main_menu',
46
46
  '=' => 'toggle_menu',
47
47
  'M-y' => 'selection_menu',
48
+ 'M-s' => 'sort_menu',
48
49
  'ENTER' => 'select_current',
49
50
  'C-p' => 'page_current',
50
51
  'C-e' => 'edit_current',
51
52
  'C-o' => 'edit_current',
52
53
  'C-s' => 'toggle_select',
54
+ 'C-r' => 'reduce',
53
55
  '@' => 'selection_mode_toggle',
54
56
  'M-a' => 'select_all',
55
57
  'M-A' => 'unselect_all',
@@ -366,25 +368,34 @@ def run
366
368
  fin = $sta + $viewport.size
367
369
  $title ||= Dir.pwd.sub(home, '~')
368
370
  clear_screen
371
+
372
+
369
373
  # title
370
374
  print "#{GREEN}#{$help} #{BLUE}cetus #{VERSION}#{CLEAR}\n"
371
375
  t = "#{$title} #{$sta + 1} to #{fin} of #{fl} #{$sorto} F:#{$filterstr}"
372
376
  t = t[t.size - $gcols..-1] if t.size >= $gcols
373
377
  print "#{BOLD}#{t}#{CLEAR}\n"
378
+
379
+
374
380
  ## nilling the title means a superimposed one gets cleared.
375
381
  # $title = nil
376
382
  # split into 2 procedures so columnate can e clean and reused.
377
383
  buff = _format $viewport
384
+
385
+ # break into as many columns as required
378
386
  buff = columnate buff, $grows
387
+
379
388
  # needed the next line to see how much extra we were going in padding
380
389
  # buff.each {|line| print "#{REVERSE}#{line}#{CLEAR}\n" }
381
390
  buff.each { |line| print line, "\n" }
382
391
  print
392
+
393
+
383
394
  # prompt
384
395
  # print "#{$files.size}, #{view.size} sta=#{sta} (#{patt}): "
385
396
  _mm = ''
386
397
  _mm = "[#{$mode}] " if $mode
387
- print "\r#{_mm}#{$patt} >"
398
+ print "\r#{_mm}#{$patt} #{GREEN}#{$message}#{CLEAR} >"
388
399
  ch = get_char
389
400
  # puts
390
401
  # break if ch == "q"
@@ -487,18 +498,42 @@ def columnate(ary, sz)
487
498
  while ctr < sz
488
499
 
489
500
  f = ary[ix]
501
+ # f is not just filename but marker and hint
502
+ # Check last char to see if directory
503
+ linecolor = nil
504
+ linecolor = BLUE if f[-1] == '/'
505
+
506
+ # check to see if we need to truncate
507
+ # TODO 2019-03-18 - truncate from middle of string.
490
508
  fsz = f.size
491
509
  if fsz > wid
492
- f = f[0, wid - 2] + '$ '
510
+ fromstart = wid - 8
511
+ # f = f[0, wid - 2] + '$ '
512
+ # 2019-03-18 - trying to truncate from center
513
+ f = f[0, fromstart] + '$' + f[-6..-1] + ' '
493
514
  ## we do the coloring after trunc so ANSI escpe seq does not get get
494
- f = "#{CURSOR_COLOR}#{f}#{CLEAR}" if ix + $sta == $cursor
515
+ if ix + $sta == $cursor
516
+ f = "#{CURSOR_COLOR}#{f}#{CLEAR}"
517
+ elsif linecolor
518
+ f = "#{linecolor}#{f}#{CLEAR}"
519
+ end
520
+
495
521
  else
496
- ## we do the coloring before padding so the entire line does not get padded, only file name
497
- f = "#{CURSOR_COLOR}#{f}#{CLEAR}" if ix + $sta == $cursor
522
+
523
+ ## we do the coloring before padding so the entire line does not get
524
+ # padded, only file name
525
+ # f = "#{CURSOR_COLOR}#{f}#{CLEAR}" if ix + $sta == $cursor
526
+ if ix + $sta == $cursor
527
+ f = "#{CURSOR_COLOR}#{f}#{CLEAR}"
528
+ else
529
+ f = "#{linecolor}#{f}#{CLEAR}" if linecolor
530
+ end
498
531
  # f = f.ljust(wid)
499
532
  f << ' ' * (wid - fsz)
533
+
500
534
  end
501
535
 
536
+ # if already a value in that line, append to it
502
537
  if buff[ctr]
503
538
  buff[ctr] += f
504
539
  else
@@ -517,6 +552,8 @@ end
517
552
  ## formats the data with number, mark and details
518
553
  # 2019-03-09 - at some time this got renamed to `format` which is a kernel
519
554
  # method and this overshadowed that method.
555
+ # NOTE: this does not do any coloring since the codes may get chopped by
556
+ # columnate method
520
557
  def _format(ary)
521
558
  # buff = Array.new
522
559
  buff = Array.new(ary.size)
@@ -534,8 +571,6 @@ def _format(ary)
534
571
  mark = SPACE
535
572
  cur = SPACE
536
573
  cur = CURMARK if ix + $sta == $cursor
537
- # TODO: add full path TESTME
538
- # mark = GMARK if $selected_files.index(ary[ix])
539
574
  mark = GMARK if selected?(ary[ix])
540
575
 
541
576
  if $long_listing
@@ -543,6 +578,7 @@ def _format(ary)
543
578
  if File.exist? f
544
579
  stat = File.stat(f)
545
580
  else
581
+ # remove last character and get stat
546
582
  last = f[-1]
547
583
  stat = File.stat(f.chop) if last == ' ' || last == '@' || last == '*'
548
584
  end
@@ -554,7 +590,8 @@ def _format(ary)
554
590
  end
555
591
 
556
592
  s = "#{ind}#{mark}#{cur}#{f}"
557
- # I cannot color the current line since format does the chopping
593
+
594
+ # NOTE: I cannot color the current line since _format does the chopping
558
595
  # so not only does the next lines alignment get skewed,
559
596
  # but also if the line is truncated
560
597
  # then the color overflows.
@@ -678,6 +715,7 @@ def run_on_current(command)
678
715
  reset_terminal
679
716
  comm = "#{command} #{f}"
680
717
  system(comm.to_s)
718
+ push_used_dirs
681
719
  setup_terminal
682
720
  end
683
721
 
@@ -721,7 +759,7 @@ def run_command(f)
721
759
  get_char
722
760
  end
723
761
 
724
- ## cd to a dir
762
+ ## cd to a dir and go to position if specified
725
763
  def change_dir(f, pos = nil)
726
764
  unless File.directory? f
727
765
  perror "#{p} is not a directory, or does not exist."
@@ -755,6 +793,7 @@ def escape
755
793
  $viewctr = 0
756
794
  $title = nil
757
795
  $filterstr = 'M'
796
+ $message = nil
758
797
  visual_block_clear
759
798
  refresh
760
799
  end
@@ -769,6 +808,7 @@ def refresh
769
808
  $title = nil
770
809
  end
771
810
 
811
+ # put directories first, then files
772
812
  def sort_file_list(_files)
773
813
  _dirs = $files.select { |f| File.directory?(f) }
774
814
  _files = $files.select { |f| File.file?(f) }
@@ -783,7 +823,6 @@ end
783
823
 
784
824
  ## select all files
785
825
  def select_all
786
- # TODO: add path TESTME
787
826
  dir = Dir.pwd
788
827
  $selected_files = $view.map { |file| File.join(dir, file) }
789
828
  end
@@ -834,6 +873,7 @@ end
834
873
  # 2019-03-15 - TODO FIXME preferable when we go into command mode
835
874
  # run a command on current or selected files. But then is it a mode, do we remain
836
875
  # there, or come out immediately ?
876
+ # 2019-03-17 - have removed this altogether. not required
837
877
  def command_mode
838
878
  if $mode == 'COM'
839
879
  $mode = nil
@@ -917,10 +957,12 @@ def print_help
917
957
  file.puts ' HELP'
918
958
 
919
959
  file.puts
920
- file.puts 'To open a file or dir press 1-9 a-z A-Z '
960
+ file.puts 'To open a file or dir press 1-9 a-z A-Z (on left of file)'
961
+ file.puts 'Ctrl-s to select file under cursor'
921
962
  file.puts 'Selection Mode: Each selection adds to selection list (toggles)'
922
963
  file.puts ' Execute commands on selected files. e.g D C-x '
923
964
  file.puts ' Upon exiting mode, selection is cleared'
965
+ file.puts 'Use left and right arrows to move through directories'
924
966
  file.puts
925
967
  ary = []
926
968
  $bindings.each_pair { |k, v| ary.push "#{k.ljust(7)} => #{v}" }
@@ -1042,19 +1084,21 @@ end
1042
1084
  def toggle_menu
1043
1085
  h = { :h => :toggle_hidden, :c => :toggle_case, :l => :toggle_long_list, '1' => :toggle_columns,
1044
1086
  :p => :toggle_pager_mode, :e => :toggle_enhanced_list }
1045
- ch, menu_text = menu 'Toggle Menu', h
1087
+ _, menu_text = menu 'Toggle Menu', h
1046
1088
  # NOTE fzfmenu returns string not symbol
1047
1089
  return unless menu_text
1048
1090
 
1049
1091
  case menu_text
1050
1092
  when :toggle_hidden
1051
1093
  $hidden = $hidden ? nil : 'D'
1052
- pause "Hidden is now #{$hidden}"
1094
+ pause "Show hidden files is now #{!$hidden.nil?}"
1095
+ message "Show hidden is now #{!$hidden.nil?}"
1053
1096
  refresh
1054
1097
  when :toggle_case
1055
1098
  # $ignorecase = $ignorecase ? "" : "i"
1056
1099
  $ignorecase = !$ignorecase
1057
- pause "Ignore Case is now #{$ignorecase}"
1100
+ pause "Ignore Case is now #{$ignorecase}"
1101
+ message "Ignore Case is now #{$ignorecase}"
1058
1102
  refresh
1059
1103
  when :toggle_columns
1060
1104
  $gviscols = 3 if $gviscols == 1
@@ -1070,8 +1114,10 @@ def toggle_menu
1070
1114
  else
1071
1115
  ENV['MANPAGER'] || ENV['PAGER']
1072
1116
  end
1117
+ message "Default command is #{$default_command}"
1073
1118
  when :toggle_enhanced_list
1074
1119
  $enhanced_mode = !$enhanced_mode
1120
+ message "Enhanced mode is #{$long_listing}"
1075
1121
 
1076
1122
  when :toggle_long_list
1077
1123
  $long_listing = !$long_listing
@@ -1082,6 +1128,7 @@ def toggle_menu
1082
1128
  x = $grows * $gviscols
1083
1129
  $pagesize = $pagesize == x ? $grows : x
1084
1130
  end
1131
+ message "Long listing is #{$long_listing}"
1085
1132
  refresh
1086
1133
  end
1087
1134
  end
@@ -1187,7 +1234,8 @@ def extras
1187
1234
  end
1188
1235
 
1189
1236
  def filter_menu
1190
- h = { :d => :dirs, :f => :files, :e => :emptydirs, '0' => :emptyfiles }
1237
+ h = { :d => :dirs, :f => :files, :e => :emptydirs, '0' => :emptyfiles,
1238
+ :r => :reduce_list, :x => :extension}
1191
1239
  ch, menu_text = menu 'Filter Menu', h
1192
1240
  files = nil
1193
1241
  case menu_text
@@ -1207,6 +1255,10 @@ def filter_menu
1207
1255
  $filterstr = '.L0'
1208
1256
  files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}.L0)'`.split("\n")
1209
1257
  $title = 'Filter: empty files'
1258
+ when :reduce_list
1259
+ files = reduce
1260
+ when :extension
1261
+ files = filter_for_current_extension
1210
1262
  end
1211
1263
  if files
1212
1264
  $files = files
@@ -1214,6 +1266,21 @@ def filter_menu
1214
1266
  end
1215
1267
  end
1216
1268
 
1269
+ def reduce pattern=nil
1270
+ unless pattern
1271
+ print 'Enter a pattern to reduce current list: '
1272
+ pattern = gets.chomp
1273
+ end
1274
+ $title = "Filter: pattern #{pattern}"
1275
+ $files = $files.select {|f| f.match(pattern)}
1276
+ end
1277
+
1278
+ def filter_for_current_extension
1279
+ extn = File.extname(current_file)
1280
+ return unless extn
1281
+ reduce extn
1282
+ end
1283
+
1217
1284
  def select_used_dirs
1218
1285
  $title = 'Used Directories'
1219
1286
  home = File.expand_path '~'
@@ -1253,6 +1320,7 @@ def post_cd
1253
1320
  $patt = nil
1254
1321
  $sta = $cursor = 0
1255
1322
  $title = nil
1323
+ $message = nil
1256
1324
  $visual_block_start = nil
1257
1325
  $stact = 0
1258
1326
  $current_dir = Dir.pwd # 2019-03-10 - so i don't keep doing in functions
@@ -1302,6 +1370,7 @@ def config_write
1302
1370
  hash['BOOKMARKS'] = $bookmarks #.select {|file| File.exist? file}
1303
1371
  writeYML hash, f1
1304
1372
  $writing = $modified = false
1373
+ message "Saved #{f1}"
1305
1374
  end
1306
1375
 
1307
1376
  # {{{ YML
@@ -1320,13 +1389,16 @@ def writeYML obj, filename
1320
1389
  end
1321
1390
  end
1322
1391
  # }}}
1392
+
1323
1393
  ## accept a character to save this dir as a bookmark
1324
1394
  def create_bookmark
1325
1395
  print 'Enter A to Z or 0-9 to create a bookmark: '
1326
1396
  ch = get_char
1327
1397
  if ch =~ /^[0-9A-Z]$/
1328
- $bookmarks[ch] = "#{Dir.pwd}:#{$cursor}"
1398
+ # $bookmarks[ch] = "#{Dir.pwd}:#{$cursor}"
1399
+ $bookmarks[ch] = Dir.pwd
1329
1400
  $modified = true
1401
+ message "Created bookmark #{ch}"
1330
1402
  else
1331
1403
  perror 'Bookmark must be upper-case character or number.'
1332
1404
  end
@@ -1437,7 +1509,10 @@ end
1437
1509
 
1438
1510
  ## create a list of dirs in which some action has happened, for saving
1439
1511
  def push_used_dirs(d = Dir.pwd)
1440
- $used_dirs.index(d) || $used_dirs.push(d)
1512
+ # $used_dirs.index(d) || $used_dirs.push(d)
1513
+ return if $used_dirs[0] == d
1514
+ $used_dirs.delete(d) if $used_dirs.index(d)
1515
+ $used_dirs.insert(0, d)
1441
1516
  end
1442
1517
 
1443
1518
  def pbold(text)
@@ -1545,13 +1620,30 @@ end
1545
1620
 
1546
1621
  ## moves column offset so we can reach unindexed columns or entries
1547
1622
  # 0 forward and any other back/prev
1548
- def column_next(dir = 0)
1549
- if dir == 0
1623
+ # direction is 0 (forward) or 1 (backward)
1624
+ # TODO 2019-03-18 - $cursor should also move
1625
+ def column_next(direction = 0)
1626
+ # right movement or panning cycles back to first column
1627
+ # leftward movement stops at first column.
1628
+ if direction == 0
1550
1629
  $stact += $grows
1551
1630
  $stact = 0 if $stact >= $viewport.size
1631
+ $cursor += $grows
1632
+ # 2019-03-18 - zero loses offset. we need to maintain it
1633
+ # $cursor = 0 if $cursor >= $viewport.size
1634
+ if $cursor >= $viewport.size
1635
+ while $cursor > 0
1636
+ $cursor -= $grows
1637
+ end
1638
+ $cursor += $grows if $cursor < 0
1639
+ end
1552
1640
  else
1553
1641
  $stact -= $grows
1642
+ $cursor -= $grows
1554
1643
  $stact = 0 if $stact < 0
1644
+ # setting cursor as zero loses the position or offset
1645
+ # We are trying to maintain offset
1646
+ $cursor += $grows if $cursor < 0
1555
1647
  end
1556
1648
  end
1557
1649
 
@@ -1636,6 +1728,7 @@ def file_actions(action = nil)
1636
1728
  if File.directory? target
1637
1729
  begin
1638
1730
  FileUtils.mv file, target
1731
+ message "Moved #{text} to #{target}"
1639
1732
  rescue StandardError => exc
1640
1733
  perror exc.to_s
1641
1734
  end
@@ -1658,6 +1751,7 @@ def file_actions(action = nil)
1658
1751
  if File.directory? target
1659
1752
  begin
1660
1753
  FileUtils.cp file, target
1754
+ message "Copied #{text} to #{target}"
1661
1755
  rescue StandardError => exc
1662
1756
  perror exc.to_s
1663
1757
  end
@@ -1830,8 +1924,9 @@ def locate
1830
1924
  end
1831
1925
  end
1832
1926
 
1833
- ## Displays files from .viminfo file, if you use some other editor which tracks files opened
1834
- # then you can modify this accordingly.
1927
+ ## Displays files from .viminfo file, if you use some other editor which
1928
+ # tracks files opened then you can modify this accordingly.
1929
+ # Neovim does not use viminfo
1835
1930
  #
1836
1931
  def viminfo
1837
1932
  file = File.expand_path('~/.viminfo')
@@ -1852,6 +1947,7 @@ def z_interface
1852
1947
  $title = 'Directories from ~/.z'
1853
1948
  $files = `sort -rn -k2 -t '|' ~/.z | cut -f1 -d '|'`.split("\n")
1854
1949
  home = ENV['HOME']
1950
+ # shorten file names
1855
1951
  $files.collect! do |f|
1856
1952
  f.sub(/#{home}/, '~')
1857
1953
  end
@@ -1889,6 +1985,7 @@ def pos
1889
1985
  $cursor
1890
1986
  end
1891
1987
 
1988
+ # move cursor to given position/line
1892
1989
  def moveto(pos)
1893
1990
  orig = $cursor
1894
1991
  $cursor = pos
@@ -1898,7 +1995,6 @@ def moveto(pos)
1898
1995
  fin = [orig, $cursor].max
1899
1996
  if $visual_mode
1900
1997
  # PWD has to be there in selction
1901
- # TODO: add full path TESTME
1902
1998
  if selected? current_file
1903
1999
  # this depends on the direction
1904
2000
  # $selected_files = $selected_files - $view[star..fin]
@@ -1948,11 +2044,11 @@ def remove_from_selection(file)
1948
2044
  end
1949
2045
 
1950
2046
  def visual_mode_toggle
2047
+ $mode = nil
1951
2048
  $visual_mode = !$visual_mode
1952
2049
  if $visual_mode
2050
+ $mode = 'VIS'
1953
2051
  $visual_block_start = $cursor
1954
- # TODO: add full path TESTME
1955
- # $selected_files.push $view[$cursor]
1956
2052
  add_to_selection current_file
1957
2053
  end
1958
2054
  end
@@ -1961,8 +2057,6 @@ def visual_block_clear
1961
2057
  if $visual_block_start
1962
2058
  star = [$visual_block_start, $cursor].min
1963
2059
  fin = [$visual_block_start, $cursor].max
1964
- # TODO: add full path TESTME
1965
- # $selected_files = $selected_files - $view[star..fin]
1966
2060
  remove_from_selection $view[star..fin]
1967
2061
  end
1968
2062
  $visual_block_start = nil
@@ -2077,8 +2171,7 @@ def newfile
2077
2171
  refresh
2078
2172
  end
2079
2173
 
2080
-
2081
-
2174
+ # convenience method to return file under cursor
2082
2175
  def current_file
2083
2176
  $view[$cursor]
2084
2177
  end
@@ -2271,6 +2364,10 @@ def get_important_files(dir)
2271
2364
  list
2272
2365
  end
2273
2366
 
2367
+ def message mess
2368
+ $message = mess
2369
+ end
2370
+
2274
2371
  Signal.trap('EXIT') do
2275
2372
  reset_terminal
2276
2373
  # 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.23'
8
+ spec.version = '0.1.24'
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.23
4
+ version: 0.1.24
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-16 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler