ruby-shell 3.4.1 → 3.4.2
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 +4 -4
- data/bin/rsh +23 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77bd4af1f0ec04f25fb48fc4bde5b1b18a50b02e046698c9cb660dafa6caa59c
|
|
4
|
+
data.tar.gz: 807220a097167fb1338c52ce8868d3fcf0a022d8cec7963cf23654daafd72e8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e84bedcc95db51816bcfd6c5ed560914898a3e661767bcd810c6dab22d8aec7fffb8904877a606e3cf9cdc1129307fd50c1db848f429165aa935d8a57f5b46d
|
|
7
|
+
data.tar.gz: 0d939b9668cd56581466acf659cc99b75652522ee5f05d5d6fdcf7eb70930da766a818dcbeef6d81597ce24e4dc9f720a6364bc5792ccad05231ba216e9fdcb2
|
data/README.md
CHANGED
|
@@ -112,7 +112,7 @@ gp branch=main
|
|
|
112
112
|
* **Define Ruby functions as shell commands**: `:defun 'weather(*args) = system("curl -s wttr.in/#{args[0] || \"oslo\"}")'`
|
|
113
113
|
* **Call like any shell command**: `weather london`
|
|
114
114
|
* **Full Ruby power**: Access to Ruby stdlib, file operations, JSON parsing, web requests, etc.
|
|
115
|
-
* **Function management**: `:defun
|
|
115
|
+
* **Function management**: `:defun` to list, `:defun -name` to remove
|
|
116
116
|
* **Syntax highlighting**: Ruby functions highlighted in bold
|
|
117
117
|
|
|
118
118
|
## Advanced Shell Features
|
|
@@ -138,7 +138,7 @@ Special commands:
|
|
|
138
138
|
* `:history` will list the command history, while `:rmhistory` will delete the history
|
|
139
139
|
* `:jobs` will list background jobs, `:fg [job_id]` brings jobs to foreground, `:bg [job_id]` resumes stopped jobs
|
|
140
140
|
* `:defun func(args) = code` defines Ruby functions callable as shell commands (persistent!)
|
|
141
|
-
* `:defun
|
|
141
|
+
* `:defun` lists all user-defined functions, `:defun -func` removes functions
|
|
142
142
|
* `:stats` shows command execution statistics, `:stats --graph` for visual charts, `:stats --clear` to reset
|
|
143
143
|
* `:bm name` or `:bookmark name` bookmark current directory, `:bm name path #tags` with tags
|
|
144
144
|
* `:bm` lists all bookmarks, just type bookmark name to jump (e.g., `work`)
|
|
@@ -309,8 +309,8 @@ weather london
|
|
|
309
309
|
|
|
310
310
|
### Function Management
|
|
311
311
|
```bash
|
|
312
|
-
:defun
|
|
313
|
-
:defun
|
|
312
|
+
:defun # List all defined functions
|
|
313
|
+
:defun -myls # Remove a function
|
|
314
314
|
```
|
|
315
315
|
|
|
316
316
|
Ruby functions have access to:
|
data/bin/rsh
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# Web_site: http://isene.com/
|
|
9
9
|
# Github: https://github.com/isene/rsh
|
|
10
10
|
# License: Public domain
|
|
11
|
-
@version = "3.4.
|
|
11
|
+
@version = "3.4.2" # Improved defun syntax: :defun lists, :defun -name removes, enhanced :help
|
|
12
12
|
|
|
13
13
|
# MODULES, CLASSES AND EXTENSIONS
|
|
14
14
|
class String # Add coloring to strings (with escaping for Readline)
|
|
@@ -1210,10 +1210,13 @@ def help
|
|
|
1210
1210
|
col1 << "Shift-TAB History search"
|
|
1211
1211
|
col1 << ""
|
|
1212
1212
|
col1 << "CORE COMMANDS:".c(@c_prompt).b
|
|
1213
|
-
col1 << ":nick a = b
|
|
1214
|
-
col1 << ":nick
|
|
1213
|
+
col1 << ":nick a = b Create alias"
|
|
1214
|
+
col1 << ":nick List all"
|
|
1215
|
+
col1 << ":nick -a Delete"
|
|
1216
|
+
col1 << ":defun f()=x Create function"
|
|
1217
|
+
col1 << ":defun List all"
|
|
1218
|
+
col1 << ":defun -f Delete"
|
|
1215
1219
|
col1 << ":bm name Bookmark"
|
|
1216
|
-
col1 << ":defun f()=x Function"
|
|
1217
1220
|
col1 << ":stats Analytics"
|
|
1218
1221
|
col1 << ":validate p=a Safety rules"
|
|
1219
1222
|
col1 << ":calc expr Calculator"
|
|
@@ -1415,10 +1418,23 @@ def bg(job_id = nil)
|
|
|
1415
1418
|
puts "Job #{job_id} no longer exists"
|
|
1416
1419
|
end
|
|
1417
1420
|
end
|
|
1418
|
-
def defun(func_def) # Define a Ruby function like: `:defun
|
|
1419
|
-
if func_def.
|
|
1421
|
+
def defun(func_def = nil) # Define a Ruby function like: `:defun myls(*args) = Dir.glob('*').each {|f| puts f}`
|
|
1422
|
+
if func_def.nil? || func_def.strip.empty?
|
|
1423
|
+
# List all defined functions
|
|
1424
|
+
puts "User-defined Ruby functions:"
|
|
1425
|
+
all_methods = singleton_class.instance_methods(false)
|
|
1426
|
+
excluded = [:defun, :defun?, :execute_conditional, :expand_braces]
|
|
1427
|
+
methods = all_methods - excluded
|
|
1428
|
+
if methods.empty?
|
|
1429
|
+
puts " (none defined)"
|
|
1430
|
+
else
|
|
1431
|
+
methods.each do |method|
|
|
1432
|
+
puts " #{method}"
|
|
1433
|
+
end
|
|
1434
|
+
end
|
|
1435
|
+
elsif func_def.match(/^\s*-/)
|
|
1420
1436
|
# Remove function
|
|
1421
|
-
func_name = func_def.sub(/^\s*-/, '')
|
|
1437
|
+
func_name = func_def.sub(/^\s*-/, '').strip
|
|
1422
1438
|
if self.respond_to?(func_name)
|
|
1423
1439
|
singleton_class.remove_method(func_name.to_sym)
|
|
1424
1440
|
@defuns.delete(func_name)
|