ruby-shell 0.7 → 0.9
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/README.md +3 -0
- data/bin/rsh +51 -26
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb807ee53179bcbc57da83b9bdbf7d46d524ad01d384c450df00c0036e636f1
|
4
|
+
data.tar.gz: '0595692866bfd1acf9afda02e157232d7e86701063cf7e5deff2654fe9a1c0d0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9349dee0b04e6f9e0d91afcb4f60d90111249b80d3820b75a4efa16fdcea26e702ba64c895f84c0e903ec018748f8a9258a369015097e9e55f81a9ee1d7d40
|
7
|
+
data.tar.gz: d0ba07abb7b5490609691cafa88fc4c4299823ae91990daab7d5616c69535b2a9e69269141bf93e45721369eaaa93defd496b94101641d2c143b4631134af02f
|
data/README.md
CHANGED
@@ -19,6 +19,9 @@ Or simply `gem install ruby-shell`.
|
|
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
|
+
* When you start to write a command, rsh will suggest the first match in the
|
23
|
+
history and present that in "toned down" letters - press the arrow right key
|
24
|
+
to accept the suggestion.
|
22
25
|
* History with simple editing
|
23
26
|
* Config file (`.rshrc`) updates on exit
|
24
27
|
* Set of simple rsh specific commands like `nick`, `nick?`, `history` and `rmhistory`
|
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.9"
|
18
18
|
|
19
19
|
# MODULES, CLASSES AND EXTENSIONS
|
20
20
|
class String # Add coloring to strings (with escaping for Readline)
|
@@ -177,9 +177,10 @@ def getchr # Process key presses
|
|
177
177
|
return chr
|
178
178
|
end
|
179
179
|
def getstr # A custom Readline-like function
|
180
|
-
@stk
|
180
|
+
@stk = 0
|
181
181
|
@pos = 0
|
182
|
-
|
182
|
+
right = false
|
183
|
+
chr = ""
|
183
184
|
@history.insert(0, "")
|
184
185
|
@history_copy = @history.map(&:clone)
|
185
186
|
while chr != "ENTER" # Keep going with readline until user presses ENTER
|
@@ -188,6 +189,16 @@ def getstr # A custom Readline-like function
|
|
188
189
|
print @prompt
|
189
190
|
row, @pos0 = @c.pos
|
190
191
|
print cmd_check(text)
|
192
|
+
begin
|
193
|
+
cmpl = @history[1..].find {|e| e =~ /^#{Regexp.escape(text)}/}
|
194
|
+
if text.length > 2 and cmpl
|
195
|
+
print cmpl[text.length..].to_s.c(@c_stamp)
|
196
|
+
right = true
|
197
|
+
else
|
198
|
+
right = false
|
199
|
+
end
|
200
|
+
rescue
|
201
|
+
end
|
191
202
|
@c.col(@pos0 + @pos)
|
192
203
|
chr = getchr
|
193
204
|
return "\n" if chr == "C-G" # Ctrl-G escapes the reasdline
|
@@ -212,6 +223,10 @@ def getstr # A custom Readline-like function
|
|
212
223
|
@pos = @history_copy[@stk].length
|
213
224
|
end
|
214
225
|
when 'RIGHT' # Move right on the readline
|
226
|
+
if right
|
227
|
+
@history_copy[@stk] = cmpl
|
228
|
+
@pos = @history_copy[@stk].length
|
229
|
+
end
|
215
230
|
@pos += 1 unless @pos >= @history_copy[@stk].length
|
216
231
|
when 'LEFT' # Move left on the readline
|
217
232
|
@pos -= 1 unless @pos <= 0
|
@@ -321,6 +336,7 @@ def tab_switch(str) # TAB completion for command switches (TAB after "-")
|
|
321
336
|
end
|
322
337
|
def tab_hist(str)
|
323
338
|
sel = @history.select {|el| el =~ /#{str}/}
|
339
|
+
sel.delete("")
|
324
340
|
hist = tabselect(sel, true)
|
325
341
|
@tabsearch = hist if hist
|
326
342
|
@pos = @tabstr.length + @tabsearch.length if hist
|
@@ -357,7 +373,7 @@ def tabselect(ary, hist=false) # Let user select from the incoming array
|
|
357
373
|
case chr
|
358
374
|
when 'C-G', 'C-C'
|
359
375
|
@c.clear_screen_down
|
360
|
-
return
|
376
|
+
return @tabsearch
|
361
377
|
when 'DOWN'
|
362
378
|
i += 1 unless i > ary.length - 2
|
363
379
|
when 'UP'
|
@@ -365,7 +381,11 @@ def tabselect(ary, hist=false) # Let user select from the incoming array
|
|
365
381
|
when 'TAB'
|
366
382
|
chr = "ENTER"
|
367
383
|
when 'BACK'
|
368
|
-
|
384
|
+
if @tabsearch == ''
|
385
|
+
@c.clear_screen_down
|
386
|
+
return ""
|
387
|
+
end
|
388
|
+
@tabsearch.chop!
|
369
389
|
hist ? tab_hist(@tabsearch) : tab_all(@tabsearch)
|
370
390
|
return @tabsearch
|
371
391
|
when /^[[:print:]]$/
|
@@ -423,7 +443,7 @@ def rshrc # Write updates to .rshrc
|
|
423
443
|
conf.sub!(/^@history.*\n/, "")
|
424
444
|
conf += "@history = #{@history.last(@histsize)}\n"
|
425
445
|
File.write(Dir.home+'/.rshrc', conf)
|
426
|
-
puts "
|
446
|
+
puts ".rshrc updated"
|
427
447
|
end
|
428
448
|
|
429
449
|
# RSH FUNCTIONS
|
@@ -480,24 +500,29 @@ end
|
|
480
500
|
|
481
501
|
# MAIN PART
|
482
502
|
loop do
|
483
|
-
@user = Etc.getpwuid(Process.euid).name # For use in @prompt
|
484
|
-
@node = Etc.uname[:nodename] # For use in @prompt
|
485
|
-
h = @history; load(Dir.home+'/.rshrc') if File.exist?(Dir.home+'/.rshrc'); @history = h # reload prompt but not history
|
486
|
-
@prompt.gsub!(/#{Dir.home}/, '~') # Simplify path in prompt
|
487
|
-
@cmd = getstr # Main work is here
|
488
|
-
hist_clean # Clean up the history
|
489
|
-
@cmd = "ls" if @cmd == "" # Default to ls when no command is given
|
490
|
-
print "\n"; @c.clear_screen_down
|
491
|
-
if @cmd == "r" # Integration with rtfm (https://github.com/isene/RTFM)
|
492
|
-
File.write("/tmp/.rshpwd", Dir.pwd)
|
493
|
-
system("rtfm /tmp/.rshpwd")
|
494
|
-
Dir.chdir(File.read("/tmp/.rshpwd"))
|
495
|
-
next
|
496
|
-
end
|
497
|
-
@cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn" if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
|
498
503
|
begin
|
504
|
+
@user = Etc.getpwuid(Process.euid).name # For use in @prompt
|
505
|
+
@node = Etc.uname[:nodename] # For use in @prompt
|
506
|
+
h = @history; load(Dir.home+'/.rshrc') if File.exist?(Dir.home+'/.rshrc'); @history = h # reload prompt but not history
|
507
|
+
@prompt.gsub!(/#{Dir.home}/, '~') # Simplify path in prompt
|
508
|
+
@cmd = getstr # Main work is here
|
509
|
+
hist_clean # Clean up the history
|
510
|
+
@cmd = "ls" if @cmd == "" # Default to ls when no command is given
|
511
|
+
print "\n"; @c.clear_screen_down
|
512
|
+
if @cmd == "r" # Integration with rtfm (https://github.com/isene/RTFM)
|
513
|
+
File.write("/tmp/.rshpwd", Dir.pwd)
|
514
|
+
system("rtfm /tmp/.rshpwd")
|
515
|
+
Dir.chdir(File.read("/tmp/.rshpwd"))
|
516
|
+
next
|
517
|
+
end
|
518
|
+
@cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn" if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
|
499
519
|
if @cmd.match(/^\s*:/) # Ruby commands are prefixed with ":"
|
500
|
-
|
520
|
+
begin
|
521
|
+
eval(@cmd[1..-1])
|
522
|
+
rescue StandardError => err
|
523
|
+
#rescue Exception => err
|
524
|
+
puts "\n#{err}"
|
525
|
+
end
|
501
526
|
else # Execute command
|
502
527
|
@cmd.sub!(/^cd (\S*).*/, '\1')
|
503
528
|
@cmd = Dir.home if @cmd == "~"
|
@@ -510,7 +535,7 @@ loop do
|
|
510
535
|
ga = @gnick.transform_keys {|k| /\b#{Regexp.escape k}\b/}
|
511
536
|
@cmd = @cmd.gsub(Regexp.union(ga.keys), @gnick)
|
512
537
|
puts "#{Time.now.strftime("%H:%M:%S")}: #{@cmd}".c(@c_stamp)
|
513
|
-
if @cmd == "
|
538
|
+
if @cmd == "f" # fzf integration (https://github.com/junegunn/fzf)
|
514
539
|
res = `#{@cmd}`.chomp
|
515
540
|
Dir.chdir(File.dirname(res))
|
516
541
|
else
|
@@ -522,7 +547,7 @@ loop do
|
|
522
547
|
end
|
523
548
|
end
|
524
549
|
rescue StandardError => err # Throw error nicely
|
525
|
-
puts "#{err}"
|
550
|
+
puts "\n#{err}"
|
526
551
|
end
|
527
552
|
end
|
528
553
|
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
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-
|
11
|
+
date: 2023-06-02 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.9: Added the feature to suggdest the first match in history when you start writing
|
16
|
+
a command - press the right arrow key to accept.'
|
16
17
|
email: g@isene.com
|
17
18
|
executables:
|
18
19
|
- rsh
|