ruby-shell 0.9 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.rshrc +16 -4
  3. data/README.md +19 -9
  4. data/bin/rsh +72 -5
  5. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eb807ee53179bcbc57da83b9bdbf7d46d524ad01d384c450df00c0036e636f1
4
- data.tar.gz: '0595692866bfd1acf9afda02e157232d7e86701063cf7e5deff2654fe9a1c0d0'
3
+ metadata.gz: 37f126a017a54cab294467b035635ce6992f4ae1d67befcd7d4a33882929be5a
4
+ data.tar.gz: 7210fde457362b3a08e793e62ecf27059e244f514bd77f7aaf8f980c47974826
5
5
  SHA512:
6
- metadata.gz: 7e9349dee0b04e6f9e0d91afcb4f60d90111249b80d3820b75a4efa16fdcea26e702ba64c895f84c0e903ec018748f8a9258a369015097e9e55f81a9ee1d7d40
7
- data.tar.gz: d0ba07abb7b5490609691cafa88fc4c4299823ae91990daab7d5616c69535b2a9e69269141bf93e45721369eaaa93defd496b94101641d2c143b4631134af02f
6
+ metadata.gz: 5690e8bed0c4efbcf3194e8a2d5e1cdfa5e339c26cee90281818e6c7d35a4b0ce3c64dbe769b67fc86ff89220304598a15a8f56844c179376ca4813b2baafa71
7
+ data.tar.gz: 4f0c21b28d1ae2f19cd28d7727e2dce0e8097479188b122092649b49080e60f9210f489155ec2e81b2d7551f3b226f7ee78229abe3814cfc3093140a0c757d38
data/.rshrc CHANGED
@@ -1,12 +1,24 @@
1
- @prompt = "#{@user}@#{@node}".c(46) + ":".c(255) + " #{Dir.pwd}/".c(196) + " ".c(7)
2
- @nick = {"ls"=>"ls --color -F", "la"=>"ls -a --color -F", "ll"=>"ls -l --color -F", "l"=>"less"}
3
- @gnick = {}
4
- @history = []
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,18 +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 `nicks`in rsh) - both for commands and general nicks
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
- * 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.
25
- * History with simple editing
26
- * Config file (`.rshrc`) updates on exit
27
- * Set of simple rsh specific commands like `nick`, `nick?`, `history` and `rmhistory`
28
- * rsh specific commands and full set of Ruby commands available via `:command`
29
- * All colors are themeable in `.rshrc`
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
30
40
 
31
41
  ## Nicks
32
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
@@ -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.9"
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
@@ -487,7 +549,8 @@ end
487
549
  # INITIAL SETUP
488
550
  begin # Load .rshrc and populate @history
489
551
  trap "SIGINT" do print "\n"; exit end
490
- load(Dir.home+'/.rshrc') if File.exist?(Dir.home+'/.rshrc') # Initial loading - to get history
552
+ firstrun unless File.exist?(Dir.home+'/.rshrc') # Initial loading - to get history
553
+ load(Dir.home+'/.rshrc')
491
554
  @c = Cursor # Initiate @c as Cursor
492
555
  @c.save # Get max row & col
493
556
  @c.row(8000)
@@ -510,9 +573,13 @@ loop do
510
573
  @cmd = "ls" if @cmd == "" # Default to ls when no command is given
511
574
  print "\n"; @c.clear_screen_down
512
575
  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"))
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)
516
583
  next
517
584
  end
518
585
  @cmd = "echo \"#{@cmd[1...]},prx,off\" | xrpn" if @cmd =~ /^\=/ # Integration with xrpn (https://github.com/isene/xrpn)
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: '0.9'
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-02 00:00:00.000000000 Z
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.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.'
15
+ 0.10: Added introduction and creation of .rshrc on first run. Improved rtfm integration.'
17
16
  email: g@isene.com
18
17
  executables:
19
18
  - rsh