ruby-shell 0.13 → 0.14
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 +62 -45
- 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: 749e7195bab599d30f9685f7f6195b0691a68754a82c0d7a0ad2a47449aabb3d
|
4
|
+
data.tar.gz: 9a0f880c651ee3b53786b76d883a3bb44bdcb7b7260a615c72226eb220f202c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47bd21ba4c0be03d47d51ec094c1ec62f3cac58de19b86d57fc263b23bdd74fe13c352ccd584816e3c8de761a1e402254d6d64d2eb6dd04971b0b8b64ee23f30
|
7
|
+
data.tar.gz: 3b477ce839dcc6811677265981e635ac37394babe40992e06ba6192b6d776615a3dfe71ad69e006a5bb2b63357d4cdf78c129aff8815f152befafb4ff5a0fcb5
|
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.14"
|
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,27 @@ 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
249
|
@history.insert(0, "")
|
251
|
-
@history_copy = @history.map(&:clone)
|
252
250
|
while chr != "ENTER" # Keep going with readline until user presses ENTER
|
253
|
-
|
251
|
+
@ci = nil
|
252
|
+
right = false
|
254
253
|
@c.clear_line
|
255
254
|
print @prompt
|
256
255
|
row, @pos0 = @c.pos
|
257
|
-
print cmd_check(
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
else
|
264
|
-
right = false
|
265
|
-
end
|
266
|
-
rescue
|
256
|
+
print cmd_check(@history[0])
|
257
|
+
@ci = @history[1..].find_index {|e| e =~ /^#{Regexp.escape(@history[0])}/}
|
258
|
+
@ci += 1 unless @ci == nil
|
259
|
+
if @history[0].length > 2 and @ci
|
260
|
+
print @history[@ci][@history[0].length..].to_s.c(@c_stamp)
|
261
|
+
right = true
|
267
262
|
end
|
268
263
|
@c.col(@pos0 + @pos)
|
269
264
|
chr = getchr
|
270
|
-
return "\n" if chr == "C-G" # Ctrl-G escapes the reasdline
|
271
265
|
case chr
|
266
|
+
when 'C-G'
|
267
|
+
@history[0] = ""
|
268
|
+
return
|
272
269
|
when 'C-C' # Ctrl-C exits gracefully but without updating .rshrc
|
273
270
|
print "\n"
|
274
271
|
exit
|
@@ -279,73 +276,80 @@ def getstr # A custom Readline-like function
|
|
279
276
|
@c.row(1)
|
280
277
|
@c.clear_screen_down
|
281
278
|
when 'UP' # Go up in history
|
282
|
-
unless @stk >= @
|
279
|
+
unless @stk >= @history.length - 1
|
283
280
|
@stk += 1
|
284
|
-
@
|
281
|
+
@history[0] = @history[@stk].dup
|
282
|
+
@pos = @history[0].length
|
285
283
|
end
|
286
284
|
when 'DOWN' # Go down in history
|
287
|
-
|
285
|
+
if @stk == 0
|
286
|
+
@history[0] = ""
|
287
|
+
@pos = 0
|
288
|
+
elsif @stk == 1
|
289
|
+
@stk -= 1
|
290
|
+
@history[0] = ""
|
291
|
+
@pos = 0
|
292
|
+
else
|
288
293
|
@stk -= 1
|
289
|
-
@
|
294
|
+
@history[0] = @history[@stk].dup
|
295
|
+
@pos = @history[0].length
|
290
296
|
end
|
291
297
|
when 'RIGHT' # Move right on the readline
|
292
298
|
if right
|
293
|
-
@
|
294
|
-
@pos = @
|
299
|
+
@history[0] = @history[@ci].dup
|
300
|
+
@pos = @history[0].length
|
295
301
|
end
|
296
|
-
@pos += 1 unless @pos >= @
|
302
|
+
@pos += 1 unless @pos >= @history[0].length
|
297
303
|
when 'LEFT' # Move left on the readline
|
298
304
|
@pos -= 1 unless @pos <= 0
|
299
305
|
when 'HOME' # Go to beginning of the readline
|
300
306
|
@pos = 0
|
301
307
|
when 'END' # Go to the end of the readline
|
302
|
-
@pos = @
|
308
|
+
@pos = @history[0].length
|
303
309
|
when 'DEL' # Delete one character
|
304
|
-
@
|
310
|
+
@history[0][@pos] = ""
|
305
311
|
when 'BACK' # Delete one character to the left
|
306
312
|
unless @pos <= 0
|
307
313
|
@pos -= 1
|
308
|
-
@
|
314
|
+
@history[0][@pos] = ""
|
309
315
|
end
|
310
316
|
when 'WBACK' # Delete one word to the left (Ctrl-W)
|
311
317
|
unless @pos == @pos0
|
312
|
-
until @
|
318
|
+
until @history[0][@pos - 1] == " " or @pos == 0
|
313
319
|
@pos -= 1
|
314
|
-
@
|
320
|
+
@history[0][@pos] = ""
|
315
321
|
end
|
316
|
-
if @
|
322
|
+
if @history[0][@pos - 1] == " "
|
317
323
|
@pos -= 1
|
318
|
-
@
|
324
|
+
@history[0][@pos] = ""
|
319
325
|
end
|
320
326
|
end
|
321
327
|
when 'C-K' # Kill/delete that entry in the history
|
322
|
-
@history_copy.delete_at(@stk)
|
323
328
|
@history.delete_at(@stk)
|
324
329
|
@stk -= 1
|
325
|
-
@
|
330
|
+
@history[0] = @history[@stk].dup
|
331
|
+
@pos = @history[0].length
|
326
332
|
when 'LDEL' # Delete readline (Ctrl-U)
|
327
|
-
@
|
333
|
+
@history[0] = ""
|
328
334
|
@pos = 0
|
329
335
|
when 'TAB' # Tab completion of dirs and files
|
330
336
|
@tabsearch =~ /^-/ ? tabbing("switch") : tabbing("all")
|
331
337
|
when 'S-TAB'
|
332
338
|
tabbing("hist")
|
333
339
|
when /^.$/
|
334
|
-
@
|
340
|
+
@history[0].insert(@pos,chr)
|
335
341
|
@pos += 1
|
336
342
|
end
|
337
343
|
while STDIN.ready?
|
338
344
|
chr = STDIN.getc
|
339
|
-
@
|
345
|
+
@history[0].insert(@pos,chr)
|
340
346
|
@pos += 1
|
341
347
|
end
|
342
348
|
end
|
343
|
-
@history.insert(0, @history_copy[@stk])
|
344
|
-
@history[0]
|
345
349
|
end
|
346
350
|
def tabbing(type)
|
347
|
-
@tabstr = @
|
348
|
-
@tabend = @
|
351
|
+
@tabstr = @history[@stk][0...@pos]
|
352
|
+
@tabend = @history[@stk][@pos..]
|
349
353
|
elements = @tabstr.split(" ")
|
350
354
|
if @tabstr.match(" $")
|
351
355
|
elements.append("")
|
@@ -368,7 +372,7 @@ def tabbing(type)
|
|
368
372
|
elsif type == 'hist'
|
369
373
|
tab_hist(@tabsearch)
|
370
374
|
end
|
371
|
-
@
|
375
|
+
@history[@stk] = @tabstr.to_s + @tabsearch.to_s + @tabend.to_s
|
372
376
|
end
|
373
377
|
def tab_all(str) # TAB completion for Dirs/files, nicks and commands
|
374
378
|
exe = []
|
@@ -552,6 +556,12 @@ def nick? # Show nicks
|
|
552
556
|
puts " General nicks:".c(@c_gnick)
|
553
557
|
@gnick.each {|key, value| puts " #{key} = #{value}"}
|
554
558
|
end
|
559
|
+
def dirs
|
560
|
+
puts "Past direactories:"
|
561
|
+
@dirs.each_with_index do |e,i|
|
562
|
+
puts "#{i}: #{e}"
|
563
|
+
end
|
564
|
+
end
|
555
565
|
|
556
566
|
# INITIAL SETUP
|
557
567
|
begin # Load .rshrc and populate @history
|
@@ -575,7 +585,10 @@ loop do
|
|
575
585
|
@node = Etc.uname[:nodename] # For use in @prompt
|
576
586
|
h = @history; load(Dir.home+'/.rshrc') if File.exist?(Dir.home+'/.rshrc'); @history = h # reload prompt but not history
|
577
587
|
@prompt.gsub!(/#{Dir.home}/, '~') # Simplify path in prompt
|
578
|
-
|
588
|
+
getstr # Main work is here
|
589
|
+
@cmd = @history[0]
|
590
|
+
@dirs.unshift(Dir.pwd)
|
591
|
+
@dirs.pop
|
579
592
|
hist_clean # Clean up the history
|
580
593
|
@cmd = "ls" if @cmd == "" # Default to ls when no command is given
|
581
594
|
print "\n"; @c.clear_screen_down
|
@@ -598,18 +611,22 @@ loop do
|
|
598
611
|
rescue Exception => err
|
599
612
|
puts "\n#{err}"
|
600
613
|
end
|
614
|
+
elsif @cmd == '#'
|
615
|
+
dirs
|
601
616
|
else # Execute command
|
617
|
+
ca = @nick.transform_keys {|k| /((^\K\s*\K)|(\|\K\s*\K))\b(?<!-)#{Regexp.escape k}\b/}
|
618
|
+
@cmd = @cmd.gsub(Regexp.union(ca.keys), @nick)
|
619
|
+
ga = @gnick.transform_keys {|k| /\b#{Regexp.escape k}\b/}
|
620
|
+
@cmd = @cmd.gsub(Regexp.union(ga.keys), @gnick)
|
602
621
|
@cmd.sub!(/^cd (\S*).*/, '\1')
|
603
622
|
@cmd = Dir.home if @cmd == "~"
|
623
|
+
@cmd = @dirs[1] if @cmd == "-"
|
624
|
+
@cmd = @dirs[@cmd.to_i] if @cmd =~ /^\d$/
|
604
625
|
dir = @cmd.strip.sub(/~/, Dir.home)
|
605
626
|
if Dir.exist?(dir)
|
606
627
|
Dir.chdir(dir)
|
607
628
|
system("git status .") if Dir.exist?(".git")
|
608
629
|
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
630
|
puts "#{Time.now.strftime("%H:%M:%S")}: #{@cmd}".c(@c_stamp)
|
614
631
|
if @cmd == "f" # fzf integration (https://github.com/junegunn/fzf)
|
615
632
|
res = `#{@cmd}`.chomp
|
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.14'
|
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-06 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.14: Reworked readline, quirks fixed. Added shortcuts to latest dir visited (number
|
16
|
+
& #) - see Readme or Github for explanation'
|
16
17
|
email: g@isene.com
|
17
18
|
executables:
|
18
19
|
- rsh
|