ruby-shell 3.1.0 → 3.3.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/PLUGIN_GUIDE.md +757 -0
  3. data/README.md +199 -15
  4. data/bin/rsh +672 -81
  5. metadata +7 -5
data/README.md CHANGED
@@ -33,7 +33,33 @@ Or simply `gem install ruby-shell`.
33
33
  * All colors are themeable in .rshrc (see github link for possibilities)
34
34
  * Copy current command line to primary selection (paste w/middle button) with `Ctrl-y`
35
35
 
36
- ## NEW in v3.1.0 - Quick Wins & Polish
36
+ ## NEW in v3.3.0 - Quote-less Syntax, Parametrized Nicks & More ⭐⭐⭐
37
+ * **No More Quotes**: Simplified syntax - `:nick la = ls -la` instead of `:nick "la = ls -la"`
38
+ * **Parametrized Nicks**: `:nick gp = git push origin {{branch}}` then use `gp branch=main`
39
+ * **Ctrl-G Multi-line Edit**: Press Ctrl-G to edit command in $EDITOR for complex scripts
40
+ * **Custom Validation Rules**: `:validate rm -rf / = block` prevents dangerous commands
41
+ * **Shell Script Support**: for/while/if loops work with full bash syntax
42
+ * **Cleaner Commands**: `:config auto_correct on`, `:bm work /tmp #dev`, `:theme dracula`
43
+ * **Simplified Architecture**: Removed :template (merged into :nick for simplicity)
44
+ * **Backward Compatible**: Old quote syntax still works for existing .rshrc files
45
+ * **Better UX**: Less typing, more powerful, feels more natural
46
+
47
+ ## v3.2.0 - Plugin System & Productivity ⭐⭐⭐
48
+ * **Plugin Architecture**: Extensible plugin system with lifecycle hooks and extension points
49
+ * **Lifecycle Hooks**: on_startup, on_command_before, on_command_after, on_prompt
50
+ * **Extension Points**: add_completions (TAB completion), add_commands (custom commands)
51
+ * **Plugin Management**: `:plugins` list/reload/enable/disable/info commands
52
+ * **Auto-loading**: Plugins in `~/.rsh/plugins/` load automatically on startup
53
+ * **Safe Execution**: Isolated plugin execution with error handling, no shell crashes
54
+ * **Example Plugins**: git_prompt (branch in prompt), command_logger (audit log), kubectl_completion (k8s shortcuts)
55
+ * **Auto-correct Typos**: `:config "auto_correct", "on"` with user confirmation (Y/n) before applying
56
+ * **Command Timing Alerts**: `:config "slow_command_threshold", "5"` warns on commands > 5 seconds
57
+ * **Inline Calculator**: `:calc 2 + 2`, `:calc "Math::PI"` - full Ruby Math library support
58
+ * **Enhanced History**: `!!` (last), `!-2` (2nd to last), `!5:7` (chain commands 5-7)
59
+ * **Stats Visualization**: `:stats --graph` for colorful ASCII bar charts with intensity colors
60
+ * **Documentation**: Complete PLUGIN_GUIDE.md with API reference and examples
61
+
62
+ ## v3.1.0 - Quick Wins & Polish ⭐
37
63
  * **Multiple Named Sessions**: Save/load different sessions - `:save_session "project"`, `:load_session "project"`
38
64
  * **Stats Export**: Export analytics to CSV/JSON - `:stats --csv` or `:stats --json`
39
65
  * **Session Auto-save**: Set `@session_autosave = 300` in .rshrc for automatic 5-minute saves
@@ -94,20 +120,23 @@ Special functions/integrations:
94
120
  * Use `:` followed by a Ruby expression to access the whole world of Ruby
95
121
 
96
122
  Special commands:
97
- * `:nick 'll = ls -l'` to make a command alias (ll) point to a command (ls -l)
98
- * `:gnick 'h = /home/me'` to make a general alias (h) point to something (/home/me)
99
- * `:nick` lists all command nicks, `:gnick` lists general nicks (NEW in v3.0)
100
- * `:nick '-name'` delete a command nick, `:gnick '-name'` delete a general nick (NEW in v3.0)
123
+ * `:nick ll = ls -l` to make a command alias (ll) point to a command (ls -l)
124
+ * `:gnick h = /home/me` to make a general alias (h) point to something (/home/me)
125
+ * `:nick` lists all command nicks, `:gnick` lists general nicks
126
+ * `:nick -name` delete a command nick, `:gnick -name` delete a general nick
101
127
  * `:history` will list the command history, while `:rmhistory` will delete the history
102
128
  * `:jobs` will list background jobs, `:fg [job_id]` brings jobs to foreground, `:bg [job_id]` resumes stopped jobs
103
- * `:defun 'func(args) = code'` defines Ruby functions callable as shell commands (now persistent!)
104
- * `:defun?` lists all user-defined functions, `:defun '-func'` removes functions
105
- * `:stats` shows command execution statistics and analytics (NEW in v3.0)
106
- * `:bm "name"` or `:bookmark "name"` bookmark current directory, `:bm "name path #tags"` with tags (NEW in v3.0)
107
- * `:bm` lists all bookmarks, just type bookmark name to jump (e.g., `work`) (NEW in v3.0)
108
- * `:bm "-name"` delete bookmark, `:bm "?tag"` search by tag (NEW in v3.0)
109
- * `:save_session "name"` saves named session, `:load_session "name"` loads session (NEW in v3.0)
110
- * `:list_sessions` shows all saved sessions, `:rmsession "name"` or `:rmsession "*"` deletes (NEW in v3.1)
129
+ * `:defun func(args) = code` defines Ruby functions callable as shell commands (persistent!)
130
+ * `:defun?` lists all user-defined functions, `:defun -func` removes functions
131
+ * `:stats` shows command execution statistics, `:stats --graph` for visual charts, `:stats --clear` to reset
132
+ * `:bm name` or `:bookmark name` bookmark current directory, `:bm name path #tags` with tags
133
+ * `:bm` lists all bookmarks, just type bookmark name to jump (e.g., `work`)
134
+ * `:bm -name` delete bookmark, `:bm ?tag` search by tag, `:bm --stats` show statistics
135
+ * `:save_session name` saves named session, `:load_session name` loads session
136
+ * `:list_sessions` shows all saved sessions, `:rmsession name` or `:rmsession *` deletes
137
+ * `:theme name` applies color scheme, `:config` manages settings, `:env` manages environment
138
+ * `:plugins` lists plugins, `:plugins disable name` disables, `:plugins reload` reloads
139
+ * `:calc expression` inline calculator with Ruby Math library
111
140
  * `:info` shows introduction and feature overview
112
141
  * `:version` Shows the rsh version number and the last published gem file version
113
142
  * `:help` will display a compact command reference in two columns
@@ -134,10 +163,82 @@ Add to your `.rshrc`:
134
163
  ```
135
164
 
136
165
  ## Moving around
137
- 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`.
166
+ 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`.
138
167
 
139
168
  ## Nicks
140
- 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 nicks with `:nick`, list gnicks with `:gnick`. Remove a nick with `:nick "-some_command"`, e.g. `:nick "-ls"` to remove an `ls` nick. Same for gnicks.
169
+
170
+ Nicks are powerful aliases that can be simple command shortcuts or complex parametrized templates.
171
+
172
+ ### Simple Nicks
173
+ ```bash
174
+ :nick ls = ls --color # Simple alias
175
+ :nick la = ls -la # Another shortcut
176
+ :nick # List all nicks
177
+ :nick -la # Delete a nick
178
+ ```
179
+
180
+ ### Parametrized Nicks (NEW in v3.3!)
181
+ Create templates with `{{placeholder}}` parameters:
182
+
183
+ ```bash
184
+ # Git shortcuts with branch parameter
185
+ :nick gp = git push origin {{branch}}
186
+ gp branch=main # Executes: git push origin main
187
+ gp branch=develop # Executes: git push origin develop
188
+
189
+ # Deployment with multiple parameters
190
+ :nick deploy = ssh {{user}}@{{host}} 'cd {{path}} && git pull'
191
+ deploy user=admin host=prod path=/var/www
192
+ # Executes: ssh admin@prod 'cd /var/www && git pull'
193
+
194
+ # Backup with source and destination
195
+ :nick backup = rsync -av {{src}} {{dest}}
196
+ backup src=/data dest=/backup
197
+ # Executes: rsync -av /data /backup
198
+ ```
199
+
200
+ **How it works:**
201
+ - Define nick with `{{param}}` placeholders
202
+ - Use with `key=value` syntax
203
+ - Parameters auto-expand and get stripped from final command
204
+ - Works with any number of parameters
205
+
206
+ ### General Nicks (gnicks)
207
+ Substitute anywhere on command line (not just commands):
208
+ ```bash
209
+ :gnick h = /home/user # Directory shortcut
210
+ :gnick # List all gnicks
211
+ :gnick -h # Delete a gnick
212
+ ```
213
+
214
+ ## Multi-line Command Editing (v3.3.0+)
215
+
216
+ Press **Ctrl-G** to edit the current command in your $EDITOR:
217
+
218
+ ```bash
219
+ # Start typing a complex command
220
+ for i in {1..10}
221
+
222
+ # Press Ctrl-G
223
+ # Your editor opens with the command
224
+ # Add more lines:
225
+ for i in {1..10}
226
+ echo "Processing: $i"
227
+ sleep 1
228
+ done
229
+
230
+ # Save and quit
231
+ # Command appears on command line (converted to single-line with ;)
232
+ # Press ENTER to execute
233
+ ```
234
+
235
+ **Perfect for:**
236
+ - Complex shell scripts
237
+ - Long commands with many options
238
+ - Multi-line constructs (for, while, if)
239
+ - Commands you want to review/edit carefully
240
+
241
+ ---
141
242
 
142
243
  ## Tab completion
143
244
  You can tab complete almost anything. Hitting `TAB` will try to complete in this priority: nicks, gnicks, commands, dirs/files. Special completions:
@@ -210,6 +311,89 @@ Ruby functions have access to:
210
311
  - JSON/XML parsing
211
312
  - And everything else Ruby can do!
212
313
 
314
+ ## Custom Validation Rules (v3.3.0+)
315
+
316
+ Create safety rules to block, confirm, warn, or log specific command patterns:
317
+
318
+ ```bash
319
+ # Block dangerous commands completely
320
+ :validate rm -rf / = block
321
+
322
+ # Require confirmation for risky operations
323
+ :validate git push --force = confirm
324
+ :validate DROP TABLE = confirm
325
+
326
+ # Show warnings but allow execution
327
+ :validate sudo = warn
328
+ :validate chmod 777 = warn
329
+
330
+ # Log specific commands for audit trail
331
+ :validate npm install = log
332
+ # Logs to ~/.rsh_validation.log
333
+
334
+ # List all rules
335
+ :validate
336
+
337
+ # Delete rule by index
338
+ :validate -1
339
+ ```
340
+
341
+ **Actions:**
342
+ - `block` - Prevent command execution completely
343
+ - `confirm` - Ask for confirmation (y/N)
344
+ - `warn` - Show warning but allow
345
+ - `log` - Silently log to ~/.rsh_validation.log
346
+
347
+ **Pattern matching:** Uses regex, so you can match complex patterns.
348
+
349
+ ---
350
+
351
+ ## Plugin System (v3.2.0+)
352
+
353
+ rsh supports a powerful plugin system for extending functionality. Plugins are Ruby classes placed in `~/.rsh/plugins/` that can:
354
+
355
+ - Add custom commands
356
+ - Add TAB completions
357
+ - Hook into command execution (before/after)
358
+ - Modify the prompt
359
+ - Access rsh internals (history, bookmarks, etc.)
360
+
361
+ **Quick Start:**
362
+ ```ruby
363
+ # Create ~/.rsh/plugins/hello.rb
364
+ class HelloPlugin
365
+ def initialize(rsh_context)
366
+ @rsh = rsh_context
367
+ end
368
+
369
+ def add_commands
370
+ {
371
+ "hello" => lambda { |*args| "Hello, #{args[0] || 'World'}!" }
372
+ }
373
+ end
374
+ end
375
+ ```
376
+
377
+ Then in rsh: `hello Geir` outputs `Hello, Geir!`
378
+
379
+ **Plugin Management:**
380
+ ```bash
381
+ :plugins # List all loaded plugins
382
+ :plugins "disable", "git_prompt" # Disable a plugin
383
+ :plugins "enable", "git_prompt" # Enable a plugin
384
+ :plugins "reload" # Reload all plugins
385
+ :plugins "info", "plugin_name" # Show plugin details
386
+ ```
387
+
388
+ **Included Example Plugins:**
389
+ - **git_prompt** - Shows current git branch in prompt
390
+ - **command_logger** - Logs all commands with timestamps (`show_log` to view)
391
+ - **kubectl_completion** - Kubernetes shortcuts and completions (k, kns, kctx)
392
+
393
+ **See PLUGIN_GUIDE.md for complete development documentation.**
394
+
395
+ ---
396
+
213
397
  ## Integrations
214
398
  rsh is integrated with the [rtfm file manager](https://github.com/isene/RTFM), with [fzf](https://github.com/junegunn/fzf) and with the programming language [XRPN](https://github.com/isene/xrpn).
215
399