ruby-shell 0.13 → 0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/bin/rsh +89 -46
- 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: 0cc8a3f3e80656d09aeb3dc8e1d4a803d0cdd4230d2e32036d0de7fb24746b19
|
4
|
+
data.tar.gz: b08319ac8b7c86c6ba235a45b03f84727e833477ea4aeb3f26a4422a19032632
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9f896f49182e320519dce320605c8c9d1cdde7cbb072379062c148a8764f546673150bb8a7e18bf7fa8d841cffeb7f89966f9500b9c99cdc9b551778dfbba2
|
7
|
+
data.tar.gz: 89fde9f621cf09e57dae9a2ce5f1182755769dc2d0ee53a91cec797ee0e1954b107f97d4cf9a879f0df13d27574d6fe19821632bc78de08137ee8f0efbbb9d7b
|
data/README.md
CHANGED
@@ -39,6 +39,9 @@ Special commands:
|
|
39
39
|
* `:history` will list the command history, while `:rmhistory` will delete the history
|
40
40
|
* `:help` will display this help text
|
41
41
|
|
42
|
+
## Moving around
|
43
|
+
While you `cd` around to different directories, you can see the last 10 directories visited via the command `:dirs` or the convenient shortcut `#`. Entering the number in the list (like `6` and ENTER) will jump you to that directory. Entering `-` will jump you back to the previous dir (equivalent of `1`. Entering `~` will get you to your home dir. If you want to bookmark a special directory, you can do that via a general nick like this: `:gnick "x = /path/to/a/dir/"` - this would bookmark the directory to the single letter `x`.
|
44
|
+
|
42
45
|
## Nicks
|
43
46
|
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.
|
44
47
|
|
@@ -52,7 +55,7 @@ rsh is integrated with the [rtfm file manager](https://github.com/isene/RTFM), w
|
|
52
55
|
|
53
56
|
Just enter the command `r` and rtfm will be launched - and when you quit the file manager, you will drop back into rsh in the directory you where you exited rtfm.
|
54
57
|
|
55
|
-
Enter the command `
|
58
|
+
Enter the command `f` to launch the fuzzy finder - select the directory/file you want, press `ENTER` and you will find yourself in the directory where that item resides.
|
56
59
|
|
57
60
|
If you start a line with "=", the rest of the line will be interpreted as an XRPN program. This gives you the full power of XRPN right at your fingertips. You can do simple stuff like this: `=13,23,*,x^2` and the answer to `(13 * 23)^2` will be given (89401) in the format that you have set in your `.xrpn/conf`. Or you can do more elaborate stuff like `=fix 6,5,sto c,time,'Time now is: ',atime,aview,pse,fix 0,lbl a,rcl c,prx,dse c,gto a`. Go crazy. Use single-quotes for any Alpha entry.
|
58
61
|
|
data/bin/rsh
CHANGED
@@ -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.15"
|
18
18
|
|
19
19
|
# MODULES, CLASSES AND EXTENSIONS
|
20
20
|
class String # Add coloring to strings (with escaping for Readline)
|
@@ -128,7 +128,7 @@ begin # Initialization
|
|
128
128
|
# Use run-mailcap instead of xgd-open? Set = true in .rshrc if iyou want run-mailcap
|
129
129
|
@runmailcap = false
|
130
130
|
# Variable initializations
|
131
|
-
@
|
131
|
+
@dirs = ["."]*10
|
132
132
|
end
|
133
133
|
|
134
134
|
# HELP TEXT
|
@@ -245,30 +245,28 @@ end
|
|
245
245
|
def getstr # A custom Readline-like function
|
246
246
|
@stk = 0
|
247
247
|
@pos = 0
|
248
|
-
right = false
|
249
248
|
chr = ""
|
250
|
-
@history.
|
251
|
-
@history_copy = @history.map(&:clone)
|
249
|
+
@history.unshift("")
|
252
250
|
while chr != "ENTER" # Keep going with readline until user presses ENTER
|
253
|
-
|
251
|
+
@ci = nil
|
252
|
+
lift = false
|
253
|
+
right = false
|
254
254
|
@c.clear_line
|
255
255
|
print @prompt
|
256
256
|
row, @pos0 = @c.pos
|
257
|
-
print cmd_check(
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
else
|
264
|
-
right = false
|
265
|
-
end
|
266
|
-
rescue
|
257
|
+
print cmd_check(@history[0])
|
258
|
+
@ci = @history[1..].find_index {|e| e =~ /^#{Regexp.escape(@history[0])}/}
|
259
|
+
@ci += 1 unless @ci == nil
|
260
|
+
if @history[0].length > 2 and @ci
|
261
|
+
print @history[@ci][@history[0].length..].to_s.c(@c_stamp)
|
262
|
+
right = true
|
267
263
|
end
|
268
264
|
@c.col(@pos0 + @pos)
|
269
265
|
chr = getchr
|
270
|
-
return "\n" if chr == "C-G" # Ctrl-G escapes the reasdline
|
271
266
|
case chr
|
267
|
+
when 'C-G'
|
268
|
+
@history[0] = ""
|
269
|
+
return
|
272
270
|
when 'C-C' # Ctrl-C exits gracefully but without updating .rshrc
|
273
271
|
print "\n"
|
274
272
|
exit
|
@@ -279,73 +277,104 @@ def getstr # A custom Readline-like function
|
|
279
277
|
@c.row(1)
|
280
278
|
@c.clear_screen_down
|
281
279
|
when 'UP' # Go up in history
|
282
|
-
|
280
|
+
if lift
|
281
|
+
@history.unshift("")
|
282
|
+
@history[0] = @history[@stk].dup
|
283
|
+
@stk += 1
|
284
|
+
end
|
285
|
+
unless @stk >= @history.length - 1
|
283
286
|
@stk += 1
|
284
|
-
@
|
287
|
+
@history[0] = @history[@stk].dup
|
288
|
+
@pos = @history[0].length
|
285
289
|
end
|
290
|
+
lift = false
|
286
291
|
when 'DOWN' # Go down in history
|
287
|
-
|
292
|
+
if lift
|
293
|
+
@history.unshift("")
|
294
|
+
@history[0] = @history[@stk].dup
|
295
|
+
@stk += 1
|
296
|
+
end
|
297
|
+
if @stk == 0
|
298
|
+
@history[0] = ""
|
299
|
+
@pos = 0
|
300
|
+
elsif @stk == 1
|
288
301
|
@stk -= 1
|
289
|
-
@
|
302
|
+
@history[0] = ""
|
303
|
+
@pos = 0
|
304
|
+
else
|
305
|
+
@stk -= 1
|
306
|
+
@history[0] = @history[@stk].dup
|
307
|
+
@pos = @history[0].length
|
290
308
|
end
|
309
|
+
lift = false
|
291
310
|
when 'RIGHT' # Move right on the readline
|
292
311
|
if right
|
293
|
-
|
294
|
-
|
312
|
+
if lift
|
313
|
+
@history.unshift("")
|
314
|
+
@history[0] = @history[@stk].dup
|
315
|
+
@stk += 1
|
316
|
+
end
|
317
|
+
@history[0] = @history[@ci].dup
|
318
|
+
@pos = @history[0].length
|
295
319
|
end
|
296
|
-
@pos += 1 unless @pos >= @
|
320
|
+
@pos += 1 unless @pos >= @history[0].length
|
297
321
|
when 'LEFT' # Move left on the readline
|
298
322
|
@pos -= 1 unless @pos <= 0
|
299
323
|
when 'HOME' # Go to beginning of the readline
|
300
324
|
@pos = 0
|
301
325
|
when 'END' # Go to the end of the readline
|
302
|
-
@pos = @
|
326
|
+
@pos = @history[0].length
|
303
327
|
when 'DEL' # Delete one character
|
304
|
-
@
|
328
|
+
@history[0][@pos] = ""
|
329
|
+
lift = true
|
305
330
|
when 'BACK' # Delete one character to the left
|
306
331
|
unless @pos <= 0
|
307
332
|
@pos -= 1
|
308
|
-
@
|
333
|
+
@history[0][@pos] = ""
|
309
334
|
end
|
335
|
+
lift = true
|
310
336
|
when 'WBACK' # Delete one word to the left (Ctrl-W)
|
311
337
|
unless @pos == @pos0
|
312
|
-
until @
|
338
|
+
until @history[0][@pos - 1] == " " or @pos == 0
|
313
339
|
@pos -= 1
|
314
|
-
@
|
340
|
+
@history[0][@pos] = ""
|
315
341
|
end
|
316
|
-
if @
|
342
|
+
if @history[0][@pos - 1] == " "
|
317
343
|
@pos -= 1
|
318
|
-
@
|
344
|
+
@history[0][@pos] = ""
|
319
345
|
end
|
320
346
|
end
|
347
|
+
lift = true
|
321
348
|
when 'C-K' # Kill/delete that entry in the history
|
322
|
-
@history_copy.delete_at(@stk)
|
323
349
|
@history.delete_at(@stk)
|
324
350
|
@stk -= 1
|
325
|
-
@
|
351
|
+
@history[0] = @history[@stk].dup
|
352
|
+
@pos = @history[0].length
|
326
353
|
when 'LDEL' # Delete readline (Ctrl-U)
|
327
|
-
@
|
354
|
+
@history[0] = ""
|
328
355
|
@pos = 0
|
356
|
+
lift = true
|
329
357
|
when 'TAB' # Tab completion of dirs and files
|
330
358
|
@tabsearch =~ /^-/ ? tabbing("switch") : tabbing("all")
|
359
|
+
lift = true
|
331
360
|
when 'S-TAB'
|
332
361
|
tabbing("hist")
|
362
|
+
lift = true
|
333
363
|
when /^.$/
|
334
|
-
@
|
364
|
+
@history[0].insert(@pos,chr)
|
335
365
|
@pos += 1
|
366
|
+
lift = true
|
336
367
|
end
|
337
368
|
while STDIN.ready?
|
338
369
|
chr = STDIN.getc
|
339
|
-
@
|
370
|
+
@history[0].insert(@pos,chr)
|
340
371
|
@pos += 1
|
341
372
|
end
|
342
373
|
end
|
343
|
-
@history.insert(0, @history_copy[@stk])
|
344
|
-
@history[0]
|
345
374
|
end
|
346
375
|
def tabbing(type)
|
347
|
-
@tabstr = @
|
348
|
-
@tabend = @
|
376
|
+
@tabstr = @history[@stk][0...@pos]
|
377
|
+
@tabend = @history[@stk][@pos..]
|
349
378
|
elements = @tabstr.split(" ")
|
350
379
|
if @tabstr.match(" $")
|
351
380
|
elements.append("")
|
@@ -368,7 +397,7 @@ def tabbing(type)
|
|
368
397
|
elsif type == 'hist'
|
369
398
|
tab_hist(@tabsearch)
|
370
399
|
end
|
371
|
-
@
|
400
|
+
@history[@stk] = @tabstr.to_s + @tabsearch.to_s + @tabend.to_s
|
372
401
|
end
|
373
402
|
def tab_all(str) # TAB completion for Dirs/files, nicks and commands
|
374
403
|
exe = []
|
@@ -552,6 +581,12 @@ def nick? # Show nicks
|
|
552
581
|
puts " General nicks:".c(@c_gnick)
|
553
582
|
@gnick.each {|key, value| puts " #{key} = #{value}"}
|
554
583
|
end
|
584
|
+
def dirs
|
585
|
+
puts "Past direactories:"
|
586
|
+
@dirs.each_with_index do |e,i|
|
587
|
+
puts "#{i}: #{e}"
|
588
|
+
end
|
589
|
+
end
|
555
590
|
|
556
591
|
# INITIAL SETUP
|
557
592
|
begin # Load .rshrc and populate @history
|
@@ -575,7 +610,11 @@ loop do
|
|
575
610
|
@node = Etc.uname[:nodename] # For use in @prompt
|
576
611
|
h = @history; load(Dir.home+'/.rshrc') if File.exist?(Dir.home+'/.rshrc'); @history = h # reload prompt but not history
|
577
612
|
@prompt.gsub!(/#{Dir.home}/, '~') # Simplify path in prompt
|
578
|
-
|
613
|
+
system("printf \"\033]0;rsh: #{Dir.pwd}\007\"") # Set Window title to path
|
614
|
+
getstr # Main work is here
|
615
|
+
@cmd = @history[0]
|
616
|
+
@dirs.unshift(Dir.pwd)
|
617
|
+
@dirs.pop
|
579
618
|
hist_clean # Clean up the history
|
580
619
|
@cmd = "ls" if @cmd == "" # Default to ls when no command is given
|
581
620
|
print "\n"; @c.clear_screen_down
|
@@ -598,18 +637,22 @@ loop do
|
|
598
637
|
rescue Exception => err
|
599
638
|
puts "\n#{err}"
|
600
639
|
end
|
640
|
+
elsif @cmd == '#'
|
641
|
+
dirs
|
601
642
|
else # Execute command
|
643
|
+
ca = @nick.transform_keys {|k| /((^\K\s*\K)|(\|\K\s*\K))\b(?<!-)#{Regexp.escape k}\b/}
|
644
|
+
@cmd = @cmd.gsub(Regexp.union(ca.keys), @nick)
|
645
|
+
ga = @gnick.transform_keys {|k| /\b#{Regexp.escape k}\b/}
|
646
|
+
@cmd = @cmd.gsub(Regexp.union(ga.keys), @gnick)
|
602
647
|
@cmd.sub!(/^cd (\S*).*/, '\1')
|
603
648
|
@cmd = Dir.home if @cmd == "~"
|
649
|
+
@cmd = @dirs[1] if @cmd == "-"
|
650
|
+
@cmd = @dirs[@cmd.to_i] if @cmd =~ /^\d$/
|
604
651
|
dir = @cmd.strip.sub(/~/, Dir.home)
|
605
652
|
if Dir.exist?(dir)
|
606
653
|
Dir.chdir(dir)
|
607
654
|
system("git status .") if Dir.exist?(".git")
|
608
655
|
else
|
609
|
-
ca = @nick.transform_keys {|k| /((^\K\s*\K)|(\|\K\s*\K))\b(?<!-)#{Regexp.escape k}\b/}
|
610
|
-
@cmd = @cmd.gsub(Regexp.union(ca.keys), @nick)
|
611
|
-
ga = @gnick.transform_keys {|k| /\b#{Regexp.escape k}\b/}
|
612
|
-
@cmd = @cmd.gsub(Regexp.union(ga.keys), @gnick)
|
613
656
|
puts "#{Time.now.strftime("%H:%M:%S")}: #{@cmd}".c(@c_stamp)
|
614
657
|
if @cmd == "f" # fzf integration (https://github.com/junegunn/fzf)
|
615
658
|
res = `#{@cmd}`.chomp
|
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.15'
|
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-08 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.15: Better stack handling for history.'
|
16
16
|
email: g@isene.com
|
17
17
|
executables:
|
18
18
|
- rsh
|