ruby-shell 0.8 → 0.10
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.
- checksums.yaml +4 -4
- data/.rshrc +16 -4
- data/README.md +19 -6
- data/bin/rsh +102 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37f126a017a54cab294467b035635ce6992f4ae1d67befcd7d4a33882929be5a
|
4
|
+
data.tar.gz: 7210fde457362b3a08e793e62ecf27059e244f514bd77f7aaf8f980c47974826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5690e8bed0c4efbcf3194e8a2d5e1cdfa5e339c26cee90281818e6c7d35a4b0ce3c64dbe769b67fc86ff89220304598a15a8f56844c179376ca4813b2baafa71
|
7
|
+
data.tar.gz: 4f0c21b28d1ae2f19cd28d7727e2dce0e8097479188b122092649b49080e60f9210f489155ec2e81b2d7551f3b226f7ee78229abe3814cfc3093140a0c757d38
|
data/.rshrc
CHANGED
@@ -1,12 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# vim: set ft=ruby sw=2 sts=2 et :
|
2
|
+
|
3
|
+
# PROMPT
|
4
|
+
# The numbers in parenthesis are 256 color codes (the '.c()' is a String extention
|
5
|
+
# to color text in the terminal. Add '.b' for bold and '.i' for italics.
|
6
|
+
if @user == "root"
|
7
|
+
@prompt = "#{@user}@#{@node}".c(160) + ":".c(255) + " #{Dir.pwd}/".c(196) + " ".c(7)
|
8
|
+
else
|
9
|
+
@prompt = "#{@user}@#{@node}".c(46) + ":".c(255) + " #{Dir.pwd}/".c(196) + " ".c(7)
|
10
|
+
end
|
11
|
+
|
12
|
+
# THEME
|
5
13
|
@c_prompt = 196 # Color for basic prompt
|
6
14
|
@c_cmd = 48 # Color for valid command
|
7
15
|
@c_nick = 51 # Color for matching nick
|
8
16
|
@c_gnick = 87 # Color for matching gnick
|
9
17
|
@c_path = 208 # Color for valid path
|
18
|
+
@c_switch = 148 # Color for switches/options
|
10
19
|
@c_tabselect = 207 # Color for selected tabcompleted item
|
11
20
|
@c_taboption = 244 # Color for unselected tabcompleted item
|
21
|
+
@c_stamp = 244 # Color for time stamp/command
|
12
22
|
|
23
|
+
# UPDATED ON CTRL-D EXIT
|
24
|
+
@nick = {"ls"=>"ls --color -F"}
|
data/README.md
CHANGED
@@ -15,15 +15,28 @@ Clone this repo and drop `rsh` into your preferred bin directory. Drop `.rshrc`
|
|
15
15
|
Or simply `gem install ruby-shell`.
|
16
16
|
|
17
17
|
# Features
|
18
|
-
* Aliases (called
|
18
|
+
* Aliases (called nicks in rsh) - both for commands and general nicks
|
19
19
|
* Syntax highlighting, matching nicks, system commands and valid dirs/files
|
20
20
|
* Tab completions for nicks, system commands, command switches and dirs/files
|
21
21
|
* Tab completion presents matches in a list to pick from
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
* rsh specific commands
|
26
|
-
*
|
22
|
+
* When you start to write a command, rsh will suggest the first match in the history and present that in "toned down" letters - press the arrow right key to accept the suggestion.
|
23
|
+
* History with editing, search
|
24
|
+
* Config file (.rshrc) updates on exit (with Ctrl-d) or not (with Ctrl-c)
|
25
|
+
* Set of simple rsh specific commands like nick, nick?, history and rmhistory
|
26
|
+
* rsh specific commands and full set of Ruby commands available via :<command>
|
27
|
+
* All colors are themeable in .rshrc (see github link for possibilities)
|
28
|
+
|
29
|
+
Special functions/integrations:
|
30
|
+
* Use `r` to launch rtfm (https://github.com/isene/RTFM) - if you have it installed
|
31
|
+
* Use `f` to launch fzf (https://github.com/junegunn/fzf) - if you have it installed
|
32
|
+
* Use `=` followed by xrpn commands separated by commas (https://github.com/isene/xrpn)
|
33
|
+
* Use `:` followed by a Ruby expression to access the whole world of Ruby
|
34
|
+
|
35
|
+
Special commands:
|
36
|
+
* `:nick 'll = ls -l'` to make a command alias (ll) point to a command (ls -l)
|
37
|
+
* `:gnick 'h = /home/me'` to make a general alias (h) point to something (/home/me)
|
38
|
+
* `:nick?` will list all command nicks and general nicks (you can edit your nicks in .rshrc)
|
39
|
+
* `:history` will list the command history, while `:rmhistory` will delete the history
|
27
40
|
|
28
41
|
## Nicks
|
29
42
|
Add command nicks (aliases) with `:nick "some_nick = some_command"`, e.g. `:nick "ls = ls --color"`. Add general nicks that will substitute anything on a command line (not just commands) like this `:gnick "some_gnick = some_command"`, e.g. `:gnick "x = /home/user/somewhere"`. List (g)nicks with `:nick?`. Remove a nick with `:nick "-some_command"`, e.g. `:nick "-ls"` to remove an `ls` nick. Same for gnicks.
|
data/bin/rsh
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
#
|
4
4
|
# SCRIPT INFO
|
5
|
-
# Name:
|
5
|
+
# Name: rsh - Ruby SHell
|
6
6
|
# Language: Pure Ruby, best viewed in VIM
|
7
7
|
# Author: Geir Isene <g@isene.com>
|
8
8
|
# Web_site: http://isene.com/
|
9
|
-
# Github: https://github.com/isene/
|
9
|
+
# Github: https://github.com/isene/rsh
|
10
10
|
# License: I release all copyright claims. This code is in the public domain.
|
11
11
|
# Permission is granted to use, copy modify, distribute, and sell
|
12
12
|
# this software for any purpose. I make no guarantee about the
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# for any damages resulting from its use. Further, I am under no
|
15
15
|
# obligation to maintain or extend this software. It is provided
|
16
16
|
# on an 'as is' basis without any expressed or implied warranty.
|
17
|
-
@version = "0.
|
17
|
+
@version = "0.10"
|
18
18
|
|
19
19
|
# MODULES, CLASSES AND EXTENSIONS
|
20
20
|
class String # Add coloring to strings (with escaping for Readline)
|
@@ -130,6 +130,68 @@ begin # Initialization
|
|
130
130
|
end
|
131
131
|
|
132
132
|
# GENERIC FUNCTIONS
|
133
|
+
def firstrun
|
134
|
+
@firstrun = <<~FIRSTRUN
|
135
|
+
Hello #{@user}, welcome to rsh - the Ruby SHell.
|
136
|
+
|
137
|
+
rsh does not attempt to compete with the grand old shells like bash and zsh.
|
138
|
+
It serves the specific needs and wants of its author. If you like it, then feel free
|
139
|
+
to ask for more or different features here: https://github.com/isene/rsh. Features:
|
140
|
+
|
141
|
+
* Aliases (called nicks in rsh) - both for commands and general nicks
|
142
|
+
* Syntax highlighting, matching nicks, system commands and valid dirs/files
|
143
|
+
* Tab completions for nicks, system commands, command switches and dirs/files
|
144
|
+
* Tab completion presents matches in a list to pick from
|
145
|
+
* When you start to write a command, rsh will suggest the first match in the history and
|
146
|
+
present that in "toned down" letters - press the arrow right key to accept the suggestion.
|
147
|
+
* History with editing, search
|
148
|
+
* Config file (.rshrc) updates on exit (with Ctrl-d) or not (with Ctrl-c)
|
149
|
+
* Set of simple rsh specific commands like nick, nick?, history and rmhistory
|
150
|
+
* rsh specific commands and full set of Ruby commands available via :<command>
|
151
|
+
* All colors are themeable in .rshrc (see github link for possibilities)
|
152
|
+
|
153
|
+
Special functions/integrations:
|
154
|
+
* Use `r` to launch rtfm (https://github.com/isene/RTFM) - if you have it installed
|
155
|
+
* Use `f` to launch fzf (https://github.com/junegunn/fzf) - if you have it installed
|
156
|
+
* Use `=` followed by xrpn commands separated by commas (https://github.com/isene/xrpn)
|
157
|
+
* Use `:` followed by a Ruby expression to access the whole world of Ruby
|
158
|
+
Special commands:
|
159
|
+
* `:nick 'll = ls -l'` to make a command alias (ll) point to a command (ls -l)
|
160
|
+
* `:gnick 'h = /home/me'` to make a general alias (h) point to something (/home/me)
|
161
|
+
* `:nick?` will list all command nicks and general nicks (you can edit your nicks in .rshrc)
|
162
|
+
* `:history` will list the command history, while `:rmhistory` will delete the history
|
163
|
+
|
164
|
+
Since there is no rsh configuration file (.rshrc), I will help you set it up to suit your needs.
|
165
|
+
FIRSTRUN
|
166
|
+
|
167
|
+
puts @firstrun
|
168
|
+
puts "The prompt you see now is the very basic rsh prompt: "
|
169
|
+
print "#{@prompt} (press ENTER)"
|
170
|
+
STDIN.gets
|
171
|
+
puts "I will now change the prompt into something more useful."
|
172
|
+
puts "Feel free to amend the prompt in your .rshrc."
|
173
|
+
rc = <<~RSHRC
|
174
|
+
# PROMPT
|
175
|
+
# The numbers in parenthesis are 256 color codes (the '.c()' is a String extention
|
176
|
+
# to color text in the terminal. Add '.b' for bold and '.i' for italics.
|
177
|
+
@prompt = "\#{@user}@\#{@node}".c(46) + ":".c(255) + " \#{Dir.pwd}/".c(196) + " ".c(7)
|
178
|
+
|
179
|
+
# THEME
|
180
|
+
@c_prompt = 196 # Color for basic prompt
|
181
|
+
@c_cmd = 48 # Color for valid command
|
182
|
+
@c_nick = 51 # Color for matching nick
|
183
|
+
@c_gnick = 87 # Color for matching gnick
|
184
|
+
@c_path = 208 # Color for valid path
|
185
|
+
@c_switch = 148 # Color for switches/options
|
186
|
+
@c_tabselect = 207 # Color for selected tabcompleted item
|
187
|
+
@c_taboption = 244 # Color for unselected tabcompleted item
|
188
|
+
@c_stamp = 244 # Color for time stamp/command
|
189
|
+
|
190
|
+
@nick = {"ls"=>"ls --color -F"}
|
191
|
+
RSHRC
|
192
|
+
File.write(Dir.home+'/.rshrc', rc)
|
193
|
+
|
194
|
+
end
|
133
195
|
def getchr # Process key presses
|
134
196
|
c = STDIN.getch
|
135
197
|
case c
|
@@ -177,9 +239,10 @@ def getchr # Process key presses
|
|
177
239
|
return chr
|
178
240
|
end
|
179
241
|
def getstr # A custom Readline-like function
|
180
|
-
@stk
|
242
|
+
@stk = 0
|
181
243
|
@pos = 0
|
182
|
-
|
244
|
+
right = false
|
245
|
+
chr = ""
|
183
246
|
@history.insert(0, "")
|
184
247
|
@history_copy = @history.map(&:clone)
|
185
248
|
while chr != "ENTER" # Keep going with readline until user presses ENTER
|
@@ -188,6 +251,16 @@ def getstr # A custom Readline-like function
|
|
188
251
|
print @prompt
|
189
252
|
row, @pos0 = @c.pos
|
190
253
|
print cmd_check(text)
|
254
|
+
begin
|
255
|
+
cmpl = @history[1..].find {|e| e =~ /^#{Regexp.escape(text)}/}
|
256
|
+
if text.length > 2 and cmpl
|
257
|
+
print cmpl[text.length..].to_s.c(@c_stamp)
|
258
|
+
right = true
|
259
|
+
else
|
260
|
+
right = false
|
261
|
+
end
|
262
|
+
rescue
|
263
|
+
end
|
191
264
|
@c.col(@pos0 + @pos)
|
192
265
|
chr = getchr
|
193
266
|
return "\n" if chr == "C-G" # Ctrl-G escapes the reasdline
|
@@ -212,6 +285,10 @@ def getstr # A custom Readline-like function
|
|
212
285
|
@pos = @history_copy[@stk].length
|
213
286
|
end
|
214
287
|
when 'RIGHT' # Move right on the readline
|
288
|
+
if right
|
289
|
+
@history_copy[@stk] = cmpl
|
290
|
+
@pos = @history_copy[@stk].length
|
291
|
+
end
|
215
292
|
@pos += 1 unless @pos >= @history_copy[@stk].length
|
216
293
|
when 'LEFT' # Move left on the readline
|
217
294
|
@pos -= 1 unless @pos <= 0
|
@@ -321,6 +398,7 @@ def tab_switch(str) # TAB completion for command switches (TAB after "-")
|
|
321
398
|
end
|
322
399
|
def tab_hist(str)
|
323
400
|
sel = @history.select {|el| el =~ /#{str}/}
|
401
|
+
sel.delete("")
|
324
402
|
hist = tabselect(sel, true)
|
325
403
|
@tabsearch = hist if hist
|
326
404
|
@pos = @tabstr.length + @tabsearch.length if hist
|
@@ -357,7 +435,7 @@ def tabselect(ary, hist=false) # Let user select from the incoming array
|
|
357
435
|
case chr
|
358
436
|
when 'C-G', 'C-C'
|
359
437
|
@c.clear_screen_down
|
360
|
-
return
|
438
|
+
return @tabsearch
|
361
439
|
when 'DOWN'
|
362
440
|
i += 1 unless i > ary.length - 2
|
363
441
|
when 'UP'
|
@@ -365,7 +443,11 @@ def tabselect(ary, hist=false) # Let user select from the incoming array
|
|
365
443
|
when 'TAB'
|
366
444
|
chr = "ENTER"
|
367
445
|
when 'BACK'
|
368
|
-
|
446
|
+
if @tabsearch == ''
|
447
|
+
@c.clear_screen_down
|
448
|
+
return ""
|
449
|
+
end
|
450
|
+
@tabsearch.chop!
|
369
451
|
hist ? tab_hist(@tabsearch) : tab_all(@tabsearch)
|
370
452
|
return @tabsearch
|
371
453
|
when /^[[:print:]]$/
|
@@ -467,7 +549,8 @@ end
|
|
467
549
|
# INITIAL SETUP
|
468
550
|
begin # Load .rshrc and populate @history
|
469
551
|
trap "SIGINT" do print "\n"; exit end
|
470
|
-
|
552
|
+
firstrun unless File.exist?(Dir.home+'/.rshrc') # Initial loading - to get history
|
553
|
+
load(Dir.home+'/.rshrc')
|
471
554
|
@c = Cursor # Initiate @c as Cursor
|
472
555
|
@c.save # Get max row & col
|
473
556
|
@c.row(8000)
|
@@ -490,17 +573,22 @@ loop do
|
|
490
573
|
@cmd = "ls" if @cmd == "" # Default to ls when no command is given
|
491
574
|
print "\n"; @c.clear_screen_down
|
492
575
|
if @cmd == "r" # Integration with rtfm (https://github.com/isene/RTFM)
|
493
|
-
|
494
|
-
|
495
|
-
|
576
|
+
t = Time.now
|
577
|
+
t0 = t.nsec.to_s
|
578
|
+
tf = "/tmp/.rshpwd" + t0
|
579
|
+
File.write(tf, Dir.pwd)
|
580
|
+
system("rtfm #{tf}")
|
581
|
+
Dir.chdir(File.read(tf))
|
582
|
+
File.delete(tf)
|
496
583
|
next
|
497
584
|
end
|
498
585
|
@cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn" if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
|
499
586
|
if @cmd.match(/^\s*:/) # Ruby commands are prefixed with ":"
|
500
587
|
begin
|
501
588
|
eval(@cmd[1..-1])
|
502
|
-
rescue
|
503
|
-
|
589
|
+
rescue StandardError => err
|
590
|
+
#rescue Exception => err
|
591
|
+
puts "\n#{err}"
|
504
592
|
end
|
505
593
|
else # Execute command
|
506
594
|
@cmd.sub!(/^cd (\S*).*/, '\1')
|
@@ -526,7 +614,7 @@ loop do
|
|
526
614
|
end
|
527
615
|
end
|
528
616
|
rescue StandardError => err # Throw error nicely
|
529
|
-
puts "#{err}"
|
617
|
+
puts "\n#{err}"
|
530
618
|
end
|
531
619
|
end
|
532
620
|
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-03 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 and more. In continual development. New in
|
15
|
-
0.
|
15
|
+
0.10: Added introduction and creation of .rshrc on first run. Improved rtfm integration.'
|
16
16
|
email: g@isene.com
|
17
17
|
executables:
|
18
18
|
- rsh
|