rtfm-filemanager 1.3.2 → 1.3.6

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rtfm +93 -26
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f00fb3e8369b16527d5a703a0f41847f78e8dbf2965e350dce6c1e6b9b728a60
4
- data.tar.gz: edd96c6dfba0f59aec85c7538493da98856e5829d4dece00b8617ef9671370b5
3
+ metadata.gz: b5c18ed2d6400377fdf9e2acf29f0ca8e4cee53fdc96fc5db49f5e9be6ed5a43
4
+ data.tar.gz: 6596098c323336814fd4fd0cdb147441ff70479580cbc6f6a441fa4f551be485
5
5
  SHA512:
6
- metadata.gz: b0679919584e4b30017c05856d42581ab3d4cf10918d95a3a90e97de3291771112c6e8e071353676e6952f4d41d528af293e34ac449f95ed9410d8266b9aeceb
7
- data.tar.gz: 11ccfce45876fcd48cfae4c2ec4f86c3bf198fea6c59f881052a2b412f3dcb31580e4fe1eca32e289faf448c86ea08f48cc352fd64361ef4dd3ce71270f4b26d
6
+ metadata.gz: 90b2cc8d115449ca2d66a92e053c33c956dad083067dcef5f750476c8a8ae8c0a6c36592da11ad29aacd831af1fc59b39a09bda2913a836354763da7f75eaba8
7
+ data.tar.gz: e1dead5ecb7189b0dedc7a48eeeab77b29b810f699bbe39f21d011115c70f63f1841b81133cb3c70b6e4d2187bc583d1e9338f150485b8ae511c6d95c79350ec
data/bin/rtfm CHANGED
@@ -72,6 +72,7 @@ DIRECTORY VIEWS
72
72
  G = Show git status for current directory
73
73
  H = Do a cryptographic hash of the current directory with subdirs
74
74
  If a previous hash was made, compare and report if there has been any change
75
+ S = Show comprehensive system info (system, CPU, filesystem, latest dmesg messages)
75
76
 
76
77
  RIGHT PANE
77
78
  ENTER = Refresh the right pane
@@ -123,6 +124,7 @@ begin # BASIC SETUP
123
124
  require 'fileutils'
124
125
  require 'io/console'
125
126
  require 'date'
127
+ require 'timeout'
126
128
  require 'curses'
127
129
  include Curses
128
130
 
@@ -186,7 +188,7 @@ begin # BASIC SETUP
186
188
  end
187
189
  end
188
190
  class Curses::Window # CLASS EXTENSION
189
- attr_accessor :fg, :bg, :attr, :text, :update, :pager, :pager_more, :pager_cmd, :locate, :nohistory
191
+ attr_accessor :fg, :bg, :attr, :text, :update, :pager, :pager_more, :pager_cmd, :locate, :nohistory
190
192
  # General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
191
193
  def clr
192
194
  self.setpos(0, 0)
@@ -226,12 +228,12 @@ def get_ls_color(type) # GET THE COLOR FOR THE FILETYPE FROM IMPORTED LS_COLORS
226
228
  return color.to_i, bold
227
229
  end
228
230
  def color_parse(input) # PARSE ANSI COLOR SEQUENCES
229
- input.gsub!( /\e\[\d;38;5;(\d+)m/, '%-%\1%-%')
230
- input.gsub!( /\e\[38;5;(\d+)m/, '%-%\1%-%')
231
+ #input.gsub!( /\e\[\d;38;5;(\d+)m/, '¤¤\1¤¤')
232
+ input.gsub!( /\e\[38;5;(\d+);*(\d*)m/, '¤¤\1¤¤\2¤¤')
231
233
  input.gsub!( /\e\[0m/, "\t")
232
- color_array = input.split("%-%")
234
+ color_array = input.split("¤¤")
233
235
  color_array = color_array.drop(1)
234
- output = color_array.each_slice(2).to_a
236
+ output = color_array.each_slice(3).to_a
235
237
  return output
236
238
  end
237
239
  def getchr # PROCESS KEY PRESSES
@@ -274,6 +276,7 @@ def main_getkey # GET KEY FROM USER
274
276
  case chr
275
277
  # BASIC KEYS
276
278
  when '?' # Show helptext in right window
279
+ @w_r.fg = 249
277
280
  w_r_info(@help)
278
281
  @w_b.update = true
279
282
  when 'r' # Refresh all windows
@@ -365,6 +368,7 @@ def main_getkey # GET KEY FROM USER
365
368
  @w_b.update = true
366
369
  when 'M' # Show marks
367
370
  @marks = @marks.sort.to_h
371
+ @w_r.fg = 147
368
372
  marks_info
369
373
  @w_r.update = false
370
374
  @w_b.update = true
@@ -438,6 +442,7 @@ def main_getkey # GET KEY FROM USER
438
442
  @w_r.update = true
439
443
  @w_b.update = true
440
444
  when 'T' # Show tagged list
445
+ @w_r.fg = 196
441
446
  tagged_info
442
447
  @w_r.update = false
443
448
  @w_b.update = true
@@ -522,6 +527,7 @@ def main_getkey # GET KEY FROM USER
522
527
  when 'O' # Show the Ordering in the bottom window (the full ls command)
523
528
  w_b_info(" Full 'ls' command: ls <@s> #{@lsbase} #{@lsall} #{@lsorder} #{@lsinvert} #{@lsuser}")
524
529
  when 'G' # Git status for selected item or current dir
530
+ @w_r.fg = 214
525
531
  if File.exist?(".git")
526
532
  w_r_info(`git status 2>/dev/null`)
527
533
  else
@@ -530,6 +536,7 @@ def main_getkey # GET KEY FROM USER
530
536
  @w_r.update = false
531
537
  @w_b.update = true
532
538
  when 'H' # Compare with previous hash status or write hash status if no existing hash
539
+ @w_r.fg = 213
533
540
  hashcmd = "\(find #{Dir.pwd} -type f -print0 | sort -z | xargs -0 sha1sum; find #{Dir.pwd}"\
534
541
  " \\( -type f -o -type d \\) -print0 | sort -z | xargs -0 stat -c '%n %a'\) | sha1sum | cut -c -40"
535
542
  begin
@@ -552,6 +559,31 @@ def main_getkey # GET KEY FROM USER
552
559
  end
553
560
  @w_r.update = true
554
561
  @w_b.update = false
562
+ when 'S' # Show comprehensive system info
563
+ @w_r.pager_cmd = ""
564
+ uname = `uname -o`.chop + " "
565
+ uname += `uname -r`.chop + " "
566
+ uname += `uname -v`.chop + " "
567
+ uname += `uname -p` + "\n"
568
+ text = [[253, 1, uname]]
569
+ mem = `free -h` + "\n"
570
+ text += [[229, 0, mem]]
571
+ cpu = "CPUs = " + `nproc`.chop + " "
572
+ cpuinfo = `lscpu`
573
+ cpu += cpuinfo[/^.*Model name:\s*(.*)/, 1] + " "
574
+ cpu += "Max: " + cpuinfo[/^.*CPU max MHz:\s*(.*)/, 1][/(.*),.*/, 1] + "MHz "
575
+ cpu += "Min: " + cpuinfo[/^.*CPU min MHz:\s*(.*)/, 1][/(.*),.*/, 1] + "MHz "
576
+ cpu += "\n\n"
577
+ text += [[154, 0, cpu]]
578
+ disk = `df -H`
579
+ text += [[123, 0, disk]]
580
+ dmesg = "\nDMESG:\n"
581
+ dmesg += `dmesg | tail -10`
582
+ text += [[213, 0, dmesg]]
583
+ @w_r.text= ansifix(text)
584
+ pager_start
585
+ pager_show
586
+ @w_r.update = false
555
587
  # RIGHT PANE
556
588
  when 'ENTER' # Refresh right pane
557
589
  @w_r.clr # First clear the window, then clear any previously showing image
@@ -626,7 +658,10 @@ def main_getkey # GET KEY FROM USER
626
658
  @w_r.pager = 0
627
659
  @w_r.pager_more = false
628
660
  end
629
- @w_r.update = true if dir != Dir.pwd
661
+ begin
662
+ @w_r.update = true if dir != Dir.pwd
663
+ rescue
664
+ end
630
665
  end
631
666
  def conf_write
632
667
  if File.exist?(Dir.home+'/.rtfm.conf')
@@ -667,6 +702,16 @@ def conf_write
667
702
  end
668
703
  File.write(Dir.home+'/.rtfm.conf', conf)
669
704
  end
705
+ def ansifix(text) # Format [[fg, attr, text]]
706
+ output = ""
707
+ text.each do |e|
708
+ ansi = "\e[38;5;#{e[0]}"
709
+ ansi += ";1" if e[1] == 1
710
+ ansi += "m"
711
+ output += ansi + e[2].gsub(/\n/, "\n#{ansi}")
712
+ end
713
+ return output
714
+ end
670
715
  # TOP WINDOW FUNCTIONS
671
716
  def w_t_info # SHOW INFO IN @w_t
672
717
  text = " " + ENV['USER'].to_s + "@" + `hostname 2>/dev/null`.to_s.chop + ": " + Dir.pwd + "/"
@@ -927,7 +972,7 @@ def w_r_info(info) # SHOW INFO IN THE RIGHT WINDOW
927
972
  image_show("clear") if @image; @image = false
928
973
  end
929
974
  def marks_info # SHOW MARKS IN RIGHT WINDOW
930
- info = "Marks:\n"
975
+ info = "MARKS:\n"
931
976
  unless @marks.empty?
932
977
  @marks.each do |mark, dir|
933
978
  info += "#{mark} = #{dir}\n"
@@ -938,19 +983,21 @@ def marks_info # SHOW MARKS IN RIGHT WINDOW
938
983
  w_r_info(info)
939
984
  end
940
985
  def tagged_info # SHOW THE LIST OF TAGGED ITEMS IN @w_r
941
- info = "Tagged:\n"
986
+ info = "TAGGED:\n"
942
987
  @tagged.empty? ? info += "(None)" : info += @tagged.join("\n")
943
988
  w_r_info(info)
944
989
  end
945
- def syntax_highlight(input) # BATCAT SYNTAX HIGHLIGHTING
990
+ def syntax_highlight(input) # SYNTAX HIGHLIGHTING FROM ANSI COLOR CODES
946
991
  color_ary = color_parse(input)
947
992
  color_ary.each do | pair |
948
993
  begin
949
994
  fg = pair[0].to_i
950
- text = pair[1]
995
+ atr = pair[1].to_i
996
+ atr == 1 ? atr = Curses::A_BOLD : atr = 0
997
+ text = pair[2]
951
998
  text.gsub!(/\t/, '')
952
999
  init_pair(fg, fg, 0)
953
- @w_r.attron(color_pair(fg)) { @w_r << text }
1000
+ @w_r.attron(color_pair(fg) | atr) { @w_r << text }
954
1001
  rescue
955
1002
  end
956
1003
  end
@@ -1004,10 +1051,17 @@ def pager_show # SHOW THE CURRENT PAGE CONTENT
1004
1051
  end_l = beg_l + @w_r.maxy - 2
1005
1052
  input = @w_r.text.lines[beg_l..end_l].join() + "\n"
1006
1053
  input.lines.count > @w_r.maxy - 2 ? @w_r.pager_more = true : @w_r.pager_more = false
1007
- if @w_r.pager_cmd.match(/batcat/)
1054
+ #if @w_r.pager_cmd.match(/batcat/)
1055
+ if @w_r.text.match(/^\e\[/)
1008
1056
  syntax_highlight(input)
1009
1057
  else
1010
- @w_r << input
1058
+ if @w_r.fg == nil
1059
+ init_pair(255, 255, 0)
1060
+ @w_r.fg = 255
1061
+ else
1062
+ init_pair(@w_r.fg, @w_r.fg, 0)
1063
+ end
1064
+ @w_r.attron(color_pair(@w_r.fg)) { @w_r << input }
1011
1065
  end
1012
1066
  (@w_r.maxy - @w_r.cury).times {@w_r.deleteln()} # Clear to bottom of window
1013
1067
  pager_add_markers
@@ -1174,17 +1228,19 @@ def w_b_exec(cmd) # EXECUTE COMMAND FROM @W_B
1174
1228
  return
1175
1229
  end
1176
1230
  begin
1177
- begin
1178
- @w_r.pager_cmd = "#{cmd} | batcat -n --color=always 2>/dev/null"
1179
- @w_r.text = `#{@w_r.pager_cmd} 2>/dev/null`
1180
- rescue
1181
- @w_r.text = `#{cmd} 2>/dev/null`
1182
- end
1183
- unless @w_r.text == "" or @w_r.text == nil
1184
- pager_start
1185
- pager_show
1186
- @w_r.update = false
1187
- end
1231
+ status = Timeout::timeout(5) {
1232
+ begin
1233
+ @w_r.pager_cmd = "#{cmd} | batcat -n --color=always 2>/dev/null"
1234
+ @w_r.text = `#{@w_r.pager_cmd} 2>/dev/null`
1235
+ rescue
1236
+ @w_r.text = `#{cmd} 2>/dev/null`
1237
+ end
1238
+ unless @w_r.text == "" or @w_r.text == nil
1239
+ pager_start
1240
+ pager_show
1241
+ @w_r.update = false
1242
+ end
1243
+ }
1188
1244
  rescue
1189
1245
  w_b_info(" Failed to execute command (#{cmd})")
1190
1246
  end
@@ -1227,6 +1283,11 @@ loop do # OUTER LOOP - CATCHING REFRESHES VIA 'r'
1227
1283
  @w_r.update = false
1228
1284
  end
1229
1285
  loop do # INNER, CORE LOOP
1286
+ begin # Jump to home dir if current dir is externally removed
1287
+ Dir.pwd
1288
+ rescue
1289
+ Dir.chdir
1290
+ end
1230
1291
  system("printf \"\033]0;RTFM: #{Dir.pwd}\007\"") # Set Window title to path
1231
1292
  ls_cmd = "ls #{@lsbase} #{@lsall} #{@lsorder} #{@lsinvert} #{@lsuser}" # Get files in current directory
1232
1293
  @files = `#{ls_cmd} 2>/dev/null`.split("\n")
@@ -1263,7 +1324,10 @@ loop do # OUTER LOOP - CATCHING REFRESHES VIA 'r'
1263
1324
  @w_l.setpos(0,0)
1264
1325
  list_dir(true)
1265
1326
  @w_l.refresh
1266
- w_r_show if @w_r.update and @preview
1327
+ if @w_r.update and @preview
1328
+ w_r_show
1329
+ @w_r.fg = 255
1330
+ end
1267
1331
  Curses.curs_set(1) # Clear residual cursor
1268
1332
  Curses.curs_set(0) # ...from editing files
1269
1333
  @tag = false # Clear tag pattern
@@ -1278,7 +1342,10 @@ loop do # OUTER LOOP - CATCHING REFRESHES VIA 'r'
1278
1342
  image_show("clear")
1279
1343
  close_screen
1280
1344
  # If launched via the script "r", return current dir and "r" will cd to that
1281
- File.write(ARGV[0], Dir.pwd) if ARGV[0] and ARGV[0].match(/\/tmp\/tmp/)
1345
+ begin
1346
+ File.write(ARGV[0], Dir.pwd) if ARGV[0] and ARGV[0].match(/\/tmp\/tmp/)
1347
+ rescue
1348
+ end
1282
1349
  end
1283
1350
  end
1284
1351
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtfm-filemanager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -33,8 +33,8 @@ dependencies:
33
33
  description: 'A full featured terminal browser with syntax highlighted files, images
34
34
  shown in the terminal, videos thumbnailed, etc. You can bookmark and jump around
35
35
  easily, delete, rename, copy, symlink and move files. RTFM has a a wide range of
36
- other features. New in 1.3.1: Added ls invert order (@lsinvert) to be written to
37
- .rtfm.conf via the W key.'
36
+ other features. New in 1.3.6: Created a better ANSI color code parser and prettified
37
+ system info (via key ''S'')'
38
38
  email: g@isene.com
39
39
  executables:
40
40
  - rtfm