cetus 0.1.22 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cetus +106 -44
  3. data/cetus.gemspec +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 040badb6cd9462f5d5a2fe5f5b5e320c03fbbd80984d71e526c500bdd0781822
4
- data.tar.gz: c48f55c076c32815785341986791e680b990b3fbf3bf1d519835b70331790a52
3
+ metadata.gz: 5b9d18e0f61df366b1977e94b4492e2d5d89db8459082859c96325bb30459cc4
4
+ data.tar.gz: 698d7c3e64d40e533d3fe1d028e2e2425d2fcd4db09cebb5803d9d64450009d5
5
5
  SHA512:
6
- metadata.gz: a7a6655724e7b3e5e46d20d8bf0cc90a3032aacdca0dbbbb4d4348c87c845e8a974574f2530781ff44a7860ed1d3f9eb8e0c5caa952411963106ac3622fc39f9
7
- data.tar.gz: c61c40989b45d3e4c2ecc04d6a04ceae2722fbf3d0d582e37fb86b4e00b5d78582c16edd18fef1c58ad86e3c20038d4ae3b5455270c7da25dba2bcdb19f27c75
6
+ metadata.gz: 55a5c875ecf98f26123a9d3f7dac5e8cdc8731fede1c3767cad9f84a117827473ccb598f2ca5fc96f2e839a5bdfd2a50ce739a16c65f4aa1205afb20d0bfa053
7
+ data.tar.gz: c444a54d8675e4c7d6953f3da43e07d1ac8f464b4f6cd835ec5e51da625e0e9ee55067ddb6fb00d8ed4cc78583515db23fca11c9b35bfe2d49eb10c2e16f3642
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-10 15:07
9
+ # Last update: 2019-03-16 10:17
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.22.0'.freeze
38
+ VERSION = '0.1.23.0'.freeze
39
39
  O_CONFIG = true
40
40
  # CONFIG_FILE = '~/.lyrainfo'.freeze
41
41
  CONFIG_FILE = '~/.config/cetus/conf.yml'.freeze
@@ -44,10 +44,16 @@ $bindings = {}
44
44
  $bindings = {
45
45
  '`' => 'main_menu',
46
46
  '=' => 'toggle_menu',
47
- '!' => 'command_mode',
47
+ 'M-y' => 'selection_menu',
48
+ 'ENTER' => 'select_current',
49
+ 'C-p' => 'page_current',
50
+ 'C-e' => 'edit_current',
51
+ 'C-o' => 'edit_current',
52
+ 'C-s' => 'toggle_select',
48
53
  '@' => 'selection_mode_toggle',
49
54
  'M-a' => 'select_all',
50
55
  'M-A' => 'unselect_all',
56
+ '!' => 'execute',
51
57
  ',' => 'goto_parent_dir',
52
58
  '~' => 'goto_home_dir',
53
59
  '-' => 'goto_previous_dir', # 2019-03-07 - added. like 'cd ='
@@ -61,18 +67,14 @@ $bindings = {
61
67
  'SPACE' => 'next_page',
62
68
  'M-f' => 'select_visited_files',
63
69
  'M-d' => 'select_used_dirs',
64
- 'M-b' => 'select_bookmarks',
70
+ 'M-b' => 'bookmark_menu',
65
71
  'M-m' => 'create_bookmark',
66
- 'M-M' => 'show_marks',
72
+ 'M-M' => 'view_bookmarks',
67
73
  'C-c' => 'escape',
68
74
  'ESCAPE' => 'escape',
69
75
  'TAB' => 'views',
70
76
  'C-i' => 'views',
71
- '?' => 'dirtree',
72
- 'ENTER' => 'select_current',
73
- 'C-p' => 'page_current',
74
- 'C-e' => 'edit_current',
75
- 'C-o' => 'edit_current',
77
+ # '?' => 'dirtree',
76
78
  'D' => 'delete_file',
77
79
  'M' => 'file_actions most',
78
80
  'q' => 'quit_command', # was Q now q 2019-03-04 -
@@ -92,7 +94,7 @@ $bindings = {
92
94
  'DOWN' => 'cursor_dn',
93
95
  'C-SPACE' => 'visual_mode_toggle',
94
96
 
95
- 'M-?' => 'print_help',
97
+ '?' => 'print_help',
96
98
  'F1' => 'print_help',
97
99
  'F2' => 'child_dirs',
98
100
  'F3' => 'dirtree',
@@ -326,9 +328,10 @@ $viewctr = 0
326
328
  $history = []
327
329
  $sta = $cursor = 0
328
330
  $visual_mode = false
329
- # $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"
331
+ # $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} Execute #{BOLD}@#{BOLD_OFF} Selection Mode #{BOLD}q#{BOLD_OFF} Quit"
330
332
 
331
- $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 "
333
+ # Menubar on top of screen
334
+ $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 "
332
335
 
333
336
  ## main loop which calls all other programs
334
337
  def run
@@ -591,7 +594,7 @@ def select_hint(view, ch)
591
594
  end
592
595
 
593
596
  ## toggle selection state of file
594
- def toggle_select(f)
597
+ def toggle_select(f=current_file)
595
598
  # dir = Dir.pwd
596
599
  # file = File.join(dir, f)
597
600
  if selected? f
@@ -680,8 +683,9 @@ end
680
683
 
681
684
  ## run command on given file/s
682
685
  # Accepts command from user
683
- # After putting readline in place of gets, pressing a C-c has a delayed effect. It goes intot
684
- # exception bloack after executing other commands and still does not do the return !
686
+ # After putting readline in place of gets, pressing a C-c has a delayed effect.
687
+ # It goes into exception block after executing other commands and still
688
+ # does not do the return !
685
689
  def run_command(f)
686
690
  files = nil
687
691
  case f
@@ -719,6 +723,10 @@ end
719
723
 
720
724
  ## cd to a dir
721
725
  def change_dir(f, pos = nil)
726
+ unless File.directory? f
727
+ perror "#{p} is not a directory, or does not exist."
728
+ return
729
+ end
722
730
  $visited_dirs.insert(0, Dir.pwd)
723
731
  f = File.expand_path(f)
724
732
  Dir.chdir f
@@ -814,8 +822,7 @@ end
814
822
  #
815
823
  def selection_mode_toggle
816
824
  if $mode == 'SEL'
817
- # we seem to be coming out of select mode with some files
818
- run_command $selected_files unless $selected_files.empty?
825
+ unselect_all
819
826
  $mode = nil
820
827
  else
821
828
  # $selection_mode = !$selection_mode
@@ -824,6 +831,9 @@ def selection_mode_toggle
824
831
  end
825
832
 
826
833
  ## toggle command mode
834
+ # 2019-03-15 - TODO FIXME preferable when we go into command mode
835
+ # run a command on current or selected files. But then is it a mode, do we remain
836
+ # there, or come out immediately ?
827
837
  def command_mode
828
838
  if $mode == 'COM'
829
839
  $mode = nil
@@ -854,6 +864,8 @@ def goto_entry_starting_with(fc = nil)
854
864
  $patt = "^#{fc}"
855
865
  end
856
866
 
867
+ # Goes to directory bookmarked with number or upper case char.
868
+ # If lower case character given, then go to first file starting with char.
857
869
  def goto_bookmark(ch = nil)
858
870
  unless ch
859
871
  print 'Enter bookmark char: '
@@ -906,10 +918,9 @@ def print_help
906
918
 
907
919
  file.puts
908
920
  file.puts 'To open a file or dir press 1-9 a-z A-Z '
909
- file.puts 'Command Mode: Will prompt for a command to run on a file, after selecting using hotkey'
910
921
  file.puts 'Selection Mode: Each selection adds to selection list (toggles)'
911
- file.puts ' Execute commands on selected files. e.g D '
912
- file.puts ' Upon exiting mode, user is prompted for a command to run on selected files'
922
+ file.puts ' Execute commands on selected files. e.g D C-x '
923
+ file.puts ' Upon exiting mode, selection is cleared'
913
924
  file.puts
914
925
  ary = []
915
926
  $bindings.each_pair { |k, v| ary.push "#{k.ljust(7)} => #{v}" }
@@ -923,7 +934,7 @@ def print_help
923
934
  end
924
935
  end #
925
936
 
926
- def show_marks
937
+ def view_bookmarks
927
938
  puts
928
939
  puts 'Bookmarks: '
929
940
  $bookmarks.each_pair { |k, v| puts "#{k.ljust(7)} => #{v}" }
@@ -951,6 +962,8 @@ def main_menu
951
962
  :s => :sort_menu,
952
963
  :F => :filter_menu,
953
964
  :c => :command_menu,
965
+ :b => :bookmark_menu,
966
+ :y => :selection_menu,
954
967
  :B => :bindkey_ext_command,
955
968
  :M => :newdir,
956
969
  '%' => :newfile,
@@ -960,6 +973,27 @@ def main_menu
960
973
  menu 'Main Menu', h
961
974
  end
962
975
 
976
+ def selection_menu
977
+ h = {
978
+ :a => :select_all,
979
+ :u => :unselect_all,
980
+ :s => :toggle_select,
981
+ '@' => 'selection_mode_toggle',
982
+ 'x' => 'visual_mode_toggle',
983
+ :v => :view_selected_files
984
+ }
985
+ menu 'Selection Menu', h
986
+ end
987
+
988
+ def bookmark_menu
989
+ h = {
990
+ :v => :view_bookmarks,
991
+ :c => :create_bookmark,
992
+ :g => :goto_bookmark
993
+ }
994
+ menu 'Bookmark Menu', h
995
+ end
996
+
963
997
  # trying out fzf instead
964
998
  # 2019-03-08 - 23:46
965
999
  # FIXME returns a String not symbol, so some callers can fail
@@ -1015,20 +1049,24 @@ def toggle_menu
1015
1049
  case menu_text
1016
1050
  when :toggle_hidden
1017
1051
  $hidden = $hidden ? nil : 'D'
1052
+ pause "Hidden is now #{$hidden}"
1018
1053
  refresh
1019
1054
  when :toggle_case
1020
1055
  # $ignorecase = $ignorecase ? "" : "i"
1021
1056
  $ignorecase = !$ignorecase
1057
+ pause "Ignore Case is now #{$ignorecase}"
1022
1058
  refresh
1023
1059
  when :toggle_columns
1024
1060
  $gviscols = 3 if $gviscols == 1
1025
1061
  # $long_listing = false if $gviscols > 1
1026
1062
  x = $grows * $gviscols
1027
1063
  $pagesize = $pagesize == x ? $grows : x
1064
+ pause "Visible columns now set to #{$gviscols}"
1028
1065
  when :toggle_pager_mode
1029
1066
  $editor_mode = !$editor_mode
1030
1067
  $default_command = if $editor_mode
1031
1068
  ENV['EDITOR'] # earlier nil # 2019-03-10 -
1069
+ # it was nil so we could set a default command
1032
1070
  else
1033
1071
  ENV['MANPAGER'] || ENV['PAGER']
1034
1072
  end
@@ -1080,18 +1118,17 @@ def sort_menu
1080
1118
  # $files =$(eval "print -rl -- ${pattern}(${MFM_LISTORDER}$filterstr)")
1081
1119
  end
1082
1120
 
1121
+ # thse need to be placed in correct position, some do nothing
1122
+ # and some like ffind have no menu item
1083
1123
  def command_menu
1084
- ##
1085
1124
  # since these involve full paths, we need more space, like only one column
1086
- #
1087
1125
  ## in these cases, getting back to the earlier dir, back to earlier listing
1088
1126
  # since we've basically overlaid the old listing
1089
- #
1090
1127
  # should be able to sort THIS listing and not rerun command. But for that I'd need to use
1091
1128
  # xargs ls -t etc rather than the zsh sort order. But we can run a filter using |.
1092
1129
  #
1093
1130
  h = { t: :today, D: :default_command, R: :remove_from_list,
1094
- v: :page_selection }
1131
+ v: :view_selected_files }
1095
1132
  h[:e] = if $editor_mode
1096
1133
  :pager_mode
1097
1134
  else
@@ -1113,7 +1150,9 @@ def command_menu
1113
1150
  $files = `zsh -c 'print -rl -- *(#{$hidden}Mm0)'`.split("\n")
1114
1151
  $title = "Today's files"
1115
1152
  when :default_command
1116
- print 'Selecting a file usually invokes $EDITOR, what command do you want to use repeatedly on selected files: '
1153
+ puts " THis no longer works"
1154
+ puts 'Selecting a file usually invokes $EDITOR'
1155
+ puts 'What command do you want to use repeatedly on selected files: '
1117
1156
  $default_command = gets.chomp
1118
1157
  if $default_command != ''
1119
1158
  print 'Second part of command (maybe blank): '
@@ -1126,6 +1165,7 @@ def command_menu
1126
1165
  end
1127
1166
  end
1128
1167
 
1168
+ # This is quite badly placed and named. Maybe these should go elsewhere
1129
1169
  def extras
1130
1170
  h = { '1' => :one_column, '2' => :multi_column, :c => :columns, :r => :config_read, :w => :config_write }
1131
1171
  ch, menu_text = menu 'Extras Menu', h
@@ -1213,8 +1253,6 @@ def post_cd
1213
1253
  $patt = nil
1214
1254
  $sta = $cursor = 0
1215
1255
  $title = nil
1216
- # 2019-03-10 - why am I clearing selected when dir changed !!! FIXME
1217
- # $selected_files = [] unless $selected_files.empty?
1218
1256
  $visual_block_start = nil
1219
1257
  $stact = 0
1220
1258
  $current_dir = Dir.pwd # 2019-03-10 - so i don't keep doing in functions
@@ -1260,7 +1298,8 @@ def config_write
1260
1298
  hash = {}
1261
1299
  hash['DIRS'] = $used_dirs.select {|dir| File.exist? dir}
1262
1300
  hash['FILES'] = $visited_files.select {|file| File.exist? file}
1263
- hash['BOOKMARKS'] = $bookmarks
1301
+ # NOTE bookmarks is a hash and contains FILE:cursor_pos
1302
+ hash['BOOKMARKS'] = $bookmarks #.select {|file| File.exist? file}
1264
1303
  writeYML hash, f1
1265
1304
  $writing = $modified = false
1266
1305
  end
@@ -1283,7 +1322,7 @@ end
1283
1322
  # }}}
1284
1323
  ## accept a character to save this dir as a bookmark
1285
1324
  def create_bookmark
1286
- print 'Enter A to Z or 0-9 for bookmark: '
1325
+ print 'Enter A to Z or 0-9 to create a bookmark: '
1287
1326
  ch = get_char
1288
1327
  if ch =~ /^[0-9A-Z]$/
1289
1328
  $bookmarks[ch] = "#{Dir.pwd}:#{$cursor}"
@@ -1293,10 +1332,12 @@ def create_bookmark
1293
1332
  end
1294
1333
  end
1295
1334
 
1335
+ # allow user to exit using :q :wq :x
1336
+ # Was this supposed to be augmented, or just remain limited like this
1337
+ # We should be able to do everything in the menus from here. TODO
1296
1338
  def subcommand
1297
- print 'Enter command: '
1339
+ print 'Enter command: q x wq p w e r h '
1298
1340
  begin
1299
- # command = gets().chomp
1300
1341
  command = Readline.readline('>', true)
1301
1342
  return if command == ''
1302
1343
  rescue Exception => ex
@@ -1321,12 +1362,20 @@ def subcommand
1321
1362
  elsif command == 'wq'
1322
1363
  $quitting = true
1323
1364
  $writing = true
1365
+ elsif command == 'w'
1366
+ config_write
1324
1367
  elsif command == 'x'
1325
1368
  $quitting = true
1326
1369
  $writing = true if $modified
1370
+ elsif command == 'e'
1371
+ edit_current
1372
+ elsif command == 'h' or command == 'help' or command = '?'
1373
+ print_help
1327
1374
  elsif command == 'p'
1328
1375
  system 'echo $PWD | pbcopy'
1329
1376
  puts 'Stored PWD in clipboard (using pbcopy)'
1377
+ else
1378
+ perror "Don't know about command #{command}. Try :h or :help"
1330
1379
  end
1331
1380
  end
1332
1381
 
@@ -1511,8 +1560,9 @@ end
1511
1560
  # 2019-03-08 - TODO when a file name changes or moves it must be removed
1512
1561
  # from selection
1513
1562
  def file_actions(action = nil)
1563
+ # only add dtrx for gz
1514
1564
  h = { d: :delete, m: :move, r: :rename, v: ENV['EDITOR'] || :vim,
1515
- c: :copy, C: :chdir, W: :remspace,
1565
+ c: :copy, C: :chdir, W: :remspace, e: :execute,
1516
1566
  l: :less, s: :most, f: :file, o: :open, x: :dtrx, z: :zip }
1517
1567
  # acttext = h[action.to_sym] || action
1518
1568
  acttext = action || ''
@@ -1561,8 +1611,9 @@ def file_actions(action = nil)
1561
1611
 
1562
1612
  when :delete
1563
1613
  delcommand = 'rmtrash'
1564
- print "#{delcommand} #{files} ?[yn]: "
1614
+ print "#{delcommand} #{text} ?[yn?]: "
1565
1615
  ch = get_char
1616
+ view_selected_files if ch == '?'
1566
1617
  return if ch != 'y'
1567
1618
 
1568
1619
  system "#{delcommand} #{files}"
@@ -1675,6 +1726,8 @@ def file_actions(action = nil)
1675
1726
  end
1676
1727
  end
1677
1728
  refresh
1729
+ when :execute
1730
+ execute
1678
1731
  else
1679
1732
  return unless menu_text
1680
1733
 
@@ -1723,6 +1776,15 @@ def bindkey_ext_command
1723
1776
  end
1724
1777
  end
1725
1778
 
1779
+ # execute a command on selected or current file
1780
+ def execute
1781
+ if $selected_files.empty?
1782
+ run_command current_file
1783
+ return
1784
+ end
1785
+ run_command $selected_files
1786
+ end
1787
+
1726
1788
  def ag
1727
1789
  print 'Enter a pattern to search (ag): '
1728
1790
  pattern = Readline.readline('>', true)
@@ -1733,10 +1795,10 @@ def ag
1733
1795
  pause
1734
1796
  files = `ag -l #{pattern}`.split("\n")
1735
1797
  if files.empty?
1736
- perror 'No files found.'
1737
- else
1738
- $files = files
1798
+ perror 'No files found for #{pattern}.'
1799
+ return
1739
1800
  end
1801
+ $files = files
1740
1802
  end
1741
1803
 
1742
1804
  def ffind
@@ -1745,9 +1807,9 @@ def ffind
1745
1807
  return if pattern == ''
1746
1808
 
1747
1809
  $title = "Files found using 'find' #{pattern}"
1748
- files = `find . -name '#{pattern}'`.split("\n")
1810
+ files = `find . -name "#{pattern}"`.split("\n")
1749
1811
  if files.empty?
1750
- perror 'No files found.'
1812
+ perror 'No files found. Try adding *'
1751
1813
  else
1752
1814
  $files = files
1753
1815
  end
@@ -1867,7 +1929,7 @@ def add_to_selection(file)
1867
1929
  $current_dir ||= Dir.pwd
1868
1930
  ff.each do |f|
1869
1931
  full = File.join($current_dir, f)
1870
- $selected_files.push full
1932
+ $selected_files.push(full) unless $selected_files.include?(full)
1871
1933
  end
1872
1934
  end
1873
1935
 
@@ -2048,8 +2110,8 @@ def scripts
2048
2110
  end
2049
2111
  # ------------- end of scripts --------------------------------#
2050
2112
 
2051
- # ------------------- page_selection ------------------ #
2052
- def page_selection
2113
+ # ------------------- view_selected_files ------------------ #
2114
+ def view_selected_files
2053
2115
  require 'tempfile'
2054
2116
  file = Tempfile.new('selected_files')
2055
2117
  begin
@@ -2061,7 +2123,7 @@ def page_selection
2061
2123
  file.unlink
2062
2124
  end
2063
2125
  end
2064
- # ------------- end of page_selection --------------------------------#
2126
+ # ------------- end of view_selected_files --------------------------------#
2065
2127
  ##
2066
2128
  # Editing of the User Dir List.
2067
2129
  # remove current entry from used dirs list, since we may not want some entries being there
@@ -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.22'
8
+ spec.version = '0.1.23'
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.22
4
+ version: 0.1.23
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-10 00:00:00.000000000 Z
11
+ date: 2019-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.0.2
75
+ rubygems_version: 3.0.3
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: lightning fast file navigator - ruby 1.9.3 .. ruby 2.6