ruby-shell 1.1 → 1.2

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/README.md +1 -1
  3. data/bin/rsh +37 -32
  4. metadata +7 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99b63b13ddf019d5fbac48dd76cbd8c53b381c46eebbf0717499e9b904015209
4
- data.tar.gz: 40c43d51e54bdf37d7bc35d5e127e824314ec7ea89956e0015f6b8673dce016d
3
+ metadata.gz: 6d3646331db7eac6ea26f07f0878354ca9b3ed9f46ebda4e2bd177d252ce67d3
4
+ data.tar.gz: deffdb053c7284ed35110c482a30adfd0ec732ce5eb0d2ea4188638cf92d1b0e
5
5
  SHA512:
6
- metadata.gz: 035ee8876b1b89dcf4cea42e9d636a167e9909a44a629c130bbd09dda0487fcbae4d07ad5e148a48d06213486774cebc6e3e804107e842ce6a2e3544ee2b70d3
7
- data.tar.gz: a5209bc92c252335efa4d07518cdab32b095c1e3c19dbae7dc2180f25e15997ed52f40c44f6186d03c668d7f6d65fd26630dd48548990f62831647d1794597fc
6
+ metadata.gz: 6dec4e805bf977dd4de28784a1e1bc4c71c7df0c865c73e479e54d053de0743b9592c4c1d331e321da23d1c1e4136709fd7fb269acb372dac50d4aa3f1196737
7
+ data.tar.gz: d50d00d2f0f9af08c1516941a808087936d512f43971eb2374b476c295137048c95bb0890960589dfdc35b9b402147d0c9d162ee1b1d75b0e6ae8b2bc541c7ed
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  The Ruby SHell
5
5
 
6
6
  # Why?
7
- Ruby is my goto language (pun kinda intended). I want full control over my tools and I like challenges that I can tinker with late at night. This is an incomplete project continually being improved. Feel free to add suggestions or code.
7
+ <img src="img/rsh-logo.jpg" align="left" width="150" height="150">Ruby is my goto language (pun kinda intended). I want full control over my tools and I like challenges that I can tinker with late at night. This is an incomplete project continually being improved. Feel free to add suggestions or code.
8
8
 
9
9
  # Design principles
10
10
  Simple. One file. Minimum external requirements.
data/bin/rsh CHANGED
@@ -7,25 +7,20 @@
7
7
  # Author: Geir Isene <g@isene.com>
8
8
  # Web_site: http://isene.com/
9
9
  # Github: https://github.com/isene/rsh
10
- # License: I release all copyright claims. This code is in the public domain.
11
- # Permission is granted to use, copy modify, distribute, and sell
12
- # this software for any purpose. I make no guarantee about the
13
- # suitability of this software for any purpose and I am not liable
14
- # for any damages resulting from its use. Further, I am under no
15
- # obligation to maintain or extend this software. It is provided
16
- # on an 'as is' basis without any expressed or implied warranty.
17
- @version = "1.1"
10
+ # License: Public domain
11
+ @version = "1.2"
18
12
 
19
13
  # MODULES, CLASSES AND EXTENSIONS
20
14
  class String # Add coloring to strings (with escaping for Readline)
21
- def c(code); color(self, "\001\e[38;5;#{code}m\002"); end
22
- def b; color(self, "\001\e[1m\002"); end
23
- def i; color(self, "\001\e[3m\002"); end
24
- def u; color(self, "\001\e[4m\002"); end
25
- def l; color(self, "\001\e[5m\002"); end
15
+ def c(code); color(self, "\001\e[38;5;#{code}m\002"); end # Color code
16
+ def b; color(self, "\001\e[1m\002"); end # Bold
17
+ def i; color(self, "\001\e[3m\002"); end # Italic
18
+ def u; color(self, "\001\e[4m\002"); end # Underline
19
+ def l; color(self, "\001\e[5m\002"); end # Blink
20
+ def r; color(self, "\001\e[7m\002"); end # Reverse
26
21
  def color(text, color_code) "#{color_code}#{text}\001\e[0m\002" end
27
22
  end
28
- module Cursor # Terminal cursor movement ANSI codes (thanks to https://github.com/piotrmurach/tty-cursor/tree/master)
23
+ module Cursor # Terminal cursor movement ANSI codes (thanks to https://github.com/piotrmurach/tty-cursor)
29
24
  module_function
30
25
  ESC = "\e".freeze
31
26
  CSI = "\e[".freeze
@@ -102,13 +97,13 @@ begin # Requires
102
97
  end
103
98
  begin # Initialization
104
99
  # Theming
105
- @c_prompt = 196 # Color for basic prompt
106
- @c_cmd = 48 # Color for valid command
107
- @c_nick = 51 # Color for matching nick
108
- @c_gnick = 87 # Color for matching gnick
109
- @c_path = 208 # Color for valid path
110
- @c_switch = 148 # Color for switches/options
111
- @c_tabselect = 207 # Color for selected tabcompleted item
100
+ @c_prompt = 10 # Color for basic prompt
101
+ @c_cmd = 2 # Color for valid command
102
+ @c_nick = 6 # Color for matching nick
103
+ @c_gnick = 14 # Color for matching gnick
104
+ @c_path = 3 # Color for valid path
105
+ @c_switch = 6 # Color for switches/options
106
+ @c_tabselect = 5 # Color for selected tabcompleted item
112
107
  @c_taboption = 244 # Color for unselected tabcompleted item
113
108
  @c_stamp = 244 # Color for time stamp/command
114
109
  # Prompt
@@ -123,12 +118,14 @@ begin # Initialization
123
118
  "/usr/bin",
124
119
  "/home/#{@user}/bin"] # Basic paths for executables if not set in .rshrc
125
120
  # History
126
- @histsize = 100 # Max history if not set in .rshrc
121
+ @histsize = 200 # Max history if not set in .rshrc
127
122
  @hloaded = false # Variable to determine if history is loaded
128
- # Use run-mailcap instead of xgd-open? Set = true in .rshrc if iyou want run-mailcap
123
+ # Use run-mailcap instead of xgd-open? Set "= true" in .rshrc if you want run-mailcap
129
124
  @runmailcap = false
130
125
  # Variable initializations
131
126
  @dirs = ["."]*10
127
+ def pre_cmd; end # User-defined function to be run BEFORE command execution
128
+ def post_cmd; end # User-defined function to be run AFTER command execution
132
129
  end
133
130
 
134
131
  # HELP TEXT
@@ -158,7 +155,7 @@ end
158
155
  Special functions/integrations:
159
156
  * Use `r` to launch rtfm (https://github.com/isene/RTFM) - if you have it installed
160
157
  * Use `f` to launch fzf (https://github.com/junegunn/fzf) - if you have it installed
161
- * Use `=` followed by xrpn commands separated by commas (https://github.com/isene/xrpn)
158
+ * Use `=` followed by xrpn commands separated by commas or double-spaces (https://github.com/isene/xrpn)
162
159
  * Use `:` followed by a Ruby expression to access the whole world of Ruby
163
160
 
164
161
  Special commands:
@@ -219,6 +216,7 @@ def getchr # Process key presses
219
216
  when '6' then chr = "PgDOWN" ; chr = "C-PgDOWN" if STDIN.getc == "^"
220
217
  when '7' then chr = "HOME" ; chr = "C-HOME" if STDIN.getc == "^"
221
218
  when '8' then chr = "END" ; chr = "C-END" if STDIN.getc == "^"
219
+ else chr = ""
222
220
  end
223
221
  when 'O' # Set Ctrl+ArrowKey equal to ArrowKey; May be used for other purposes in the future
224
222
  case STDIN.getc
@@ -226,6 +224,7 @@ def getchr # Process key presses
226
224
  when 'b' then chr = "C-DOWN"
227
225
  when 'c' then chr = "C-RIGHT"
228
226
  when 'd' then chr = "C-LEFT"
227
+ else chr = ""
229
228
  end
230
229
  end
231
230
  when "", "" then chr = "BACK"
@@ -245,6 +244,7 @@ def getchr # Process key presses
245
244
  when "\r" then chr = "ENTER"
246
245
  when "\t" then chr = "TAB"
247
246
  when /[[:print:]]/ then chr = c
247
+ else chr = ""
248
248
  end
249
249
  return chr
250
250
  end
@@ -261,9 +261,9 @@ def getstr # A custom Readline-like function
261
261
  print @prompt
262
262
  row, @pos0 = @c.pos
263
263
  print cmd_check(@history[0])
264
- @ci = @history[1..].find_index {|e| e =~ /^#{Regexp.escape(@history[0])}/}
264
+ @ci = @history[1..].find_index {|e| e =~ /^#{Regexp.escape(@history[0])}./}
265
265
  @ci += 1 unless @ci == nil
266
- if @history[0].length > 2 and @ci
266
+ if @history[0].length > 1 and @ci
267
267
  print @history[@ci][@history[0].length..].to_s.c(@c_stamp)
268
268
  right = true
269
269
  end
@@ -502,11 +502,11 @@ def tabselect(ary, hist=false) # Let user select from the incoming array
502
502
  when 'TAB'
503
503
  chr = "ENTER"
504
504
  when 'BACK'
505
+ @tabsearch.chop!
505
506
  if @tabsearch == ''
506
507
  @c.clear_screen_down
507
508
  return ""
508
509
  end
509
- @tabsearch.chop!
510
510
  hist ? tab_hist(@tabsearch) : tab_all(@tabsearch)
511
511
  return @tabsearch
512
512
  when /^[[:print:]]$/
@@ -610,9 +610,9 @@ def gnick(nick_str) # Define a generic/global nick to match not only commands (f
610
610
  end
611
611
  def nick? # Show nicks
612
612
  puts " Command nicks:".c(@c_nick)
613
- @nick.each {|key, value| puts " #{key} = #{value}"}
613
+ @nick.sort.each {|key, value| puts " #{key} = #{value}"}
614
614
  puts " General nicks:".c(@c_gnick)
615
- @gnick.each {|key, value| puts " #{key} = #{value}"}
615
+ @gnick.sort.each {|key, value| puts " #{key} = #{value}"}
616
616
  end
617
617
  def dirs
618
618
  puts "Past direactories:"
@@ -676,7 +676,10 @@ loop do
676
676
  system("git status .") if Dir.exist?(".git")
677
677
  next
678
678
  end
679
- @cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn" if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
679
+ if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
680
+ @cmd.gsub!(" ", ",")
681
+ @cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn"
682
+ end
680
683
  if @cmd.match(/^\s*:/) # Ruby commands are prefixed with ":"
681
684
  begin
682
685
  eval(@cmd[1..-1])
@@ -689,7 +692,7 @@ loop do
689
692
  else # Execute command
690
693
  ca = @nick.transform_keys {|k| /((^\K\s*\K)|(\|\K\s*\K))\b(?<!-)#{Regexp.escape k}\b/}
691
694
  @cmd = @cmd.gsub(Regexp.union(ca.keys), @nick)
692
- ga = @gnick.transform_keys {|k| /\b#{Regexp.escape k}\b/}
695
+ ga = @gnick.transform_keys {|k| /\b(?<!-)#{Regexp.escape k}\b/}
693
696
  @cmd = @cmd.gsub(Regexp.union(ga.keys), @gnick)
694
697
  @cmd = "~" if @cmd == "cd"
695
698
  @cmd.sub!(/^cd (\S*).*/, '\1')
@@ -717,7 +720,9 @@ loop do
717
720
  end
718
721
  else
719
722
  begin
720
- puts "No such command or nick: #{@cmd}" unless system (@cmd) # Try execute the command
723
+ pre_cmd
724
+ puts "Not executed: #{@cmd}" unless system (@cmd) # Try execute the command
725
+ post_cmd
721
726
  rescue StandardError => err
722
727
  puts "\n#{err}"
723
728
  end
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
11
+ date: 2024-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'A shell written in Ruby with extensive tab completions, aliases/nicks,
14
14
  history, syntax highlighting, theming, auto-cd, auto-opening files and more. In
15
- continual development. New in 1.1: Added; Copy current command line to primary selection
16
- (paste w/middle button) with Ctrl-y'
15
+ continual development. New in 1.2: Fixed bug on tab handling'
17
16
  email: g@isene.com
18
17
  executables:
19
18
  - rsh
@@ -28,7 +27,7 @@ licenses:
28
27
  - Unlicense
29
28
  metadata:
30
29
  source_code_uri: https://github.com/isene/rsh
31
- post_install_message:
30
+ post_install_message:
32
31
  rdoc_options: []
33
32
  require_paths:
34
33
  - lib
@@ -43,8 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
42
  - !ruby/object:Gem::Version
44
43
  version: '0'
45
44
  requirements: []
46
- rubygems_version: 3.3.5
47
- signing_key:
45
+ rubygems_version: 3.4.20
46
+ signing_key:
48
47
  specification_version: 4
49
48
  summary: rsh - Ruby SHell
50
49
  test_files: []