ruby-shell 3.4.3 → 3.4.4
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/bin/rsh +79 -35
- 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: 587406cf97c8f8aeba405779d229d073b0c8963b24c224edd1a24d72441411d5
|
|
4
|
+
data.tar.gz: aa4ea0471988e2004e057c575684f6d2a3f2b3875872e49ee769f22045d52bd5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fc3e11246348f5eae8bec22ac1d62d990a5ab2727573202363a9c04d6f6e8448bb265fd776ae664004249ac9133baf12a78042da5045b8fe3589e8484414221
|
|
7
|
+
data.tar.gz: a4305bfba19e86a643440a4d6727e71c3e5d74467fdb9ccf5070345f66a5792256276b299e04714e389d6801e5aadf0253b3da645203bb4135412f5ffa9ec9a2
|
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.4" # Split .rshrc/.rshstate, performance improvements, symlink colors, auto-migration
|
|
12
12
|
|
|
13
13
|
# MODULES, CLASSES AND EXTENSIONS
|
|
14
14
|
class String # Add coloring to strings (with escaping for Readline)
|
|
@@ -1233,14 +1233,19 @@ end
|
|
|
1233
1233
|
def get_file_color(filename) # Get color for a file based on LS_COLORS
|
|
1234
1234
|
return 7 unless @ls_colors # Default to white if not initialized
|
|
1235
1235
|
|
|
1236
|
+
# Remove quotes and trailing slash for checking
|
|
1237
|
+
clean_name = filename.gsub(/['"]/, '').chomp('/')
|
|
1238
|
+
|
|
1239
|
+
# Check if it's a symlink (before directory check!)
|
|
1240
|
+
if File.symlink?(clean_name)
|
|
1241
|
+
return @ls_colors['ln'] || 14 # Symlinks get special color
|
|
1242
|
+
end
|
|
1243
|
+
|
|
1236
1244
|
# Check if it's a directory
|
|
1237
1245
|
if filename.end_with?('/')
|
|
1238
1246
|
return @ls_colors['di'] || 33
|
|
1239
1247
|
end
|
|
1240
1248
|
|
|
1241
|
-
# Remove quotes and trailing slash for checking
|
|
1242
|
-
clean_name = filename.gsub(/['"]/, '').chomp('/')
|
|
1243
|
-
|
|
1244
1249
|
# Check if file exists and is executable
|
|
1245
1250
|
if File.exist?(clean_name) && File.executable?(clean_name) && !File.directory?(clean_name)
|
|
1246
1251
|
return @ls_colors['ex'] || 2
|
|
@@ -1338,21 +1343,19 @@ def cmd_check(str) # Check if each element on the readline matches commands, nic
|
|
|
1338
1343
|
end
|
|
1339
1344
|
end
|
|
1340
1345
|
end
|
|
1341
|
-
def rshrc # Write
|
|
1342
|
-
hist_clean
|
|
1346
|
+
def rshrc # Write user configuration to .rshrc (portable between machines)
|
|
1347
|
+
hist_clean # Clean history before saving
|
|
1343
1348
|
if File.exist?(Dir.home+'/.rshrc')
|
|
1344
1349
|
conf = File.read(Dir.home+'/.rshrc')
|
|
1345
1350
|
else
|
|
1346
1351
|
conf = ""
|
|
1347
1352
|
end
|
|
1353
|
+
|
|
1354
|
+
# Only update user-editable items in .rshrc
|
|
1348
1355
|
conf.sub!(/^@nick.*(\n|$)/, "")
|
|
1349
1356
|
conf += "@nick = #{@nick}\n"
|
|
1350
1357
|
conf.sub!(/^@gnick.*(\n|$)/, "")
|
|
1351
1358
|
conf += "@gnick = #{@gnick}\n"
|
|
1352
|
-
conf.sub!(/^@cmd_frequency.*(\n|$)/, "")
|
|
1353
|
-
conf += "@cmd_frequency = #{@cmd_frequency}\n"
|
|
1354
|
-
conf.sub!(/^@cmd_stats.*(\n|$)/, "")
|
|
1355
|
-
conf += "@cmd_stats = #{@cmd_stats}\n" unless @cmd_stats.empty?
|
|
1356
1359
|
conf.sub!(/^@bookmarks.*(\n|$)/, "")
|
|
1357
1360
|
conf += "@bookmarks = #{@bookmarks}\n" unless @bookmarks.empty?
|
|
1358
1361
|
conf.sub!(/^@defuns.*(\n|$)/, "")
|
|
@@ -1365,40 +1368,71 @@ def rshrc # Write updates to .rshrc
|
|
|
1365
1368
|
conf += "@auto_correct = #{@auto_correct}\n" if @auto_correct
|
|
1366
1369
|
conf.sub!(/^@slow_command_threshold.*(\n|$)/, "")
|
|
1367
1370
|
conf += "@slow_command_threshold = #{@slow_command_threshold}\n" if @slow_command_threshold && @slow_command_threshold > 0
|
|
1371
|
+
conf.sub!(/^@completion_learning.*(\n|$)/, "")
|
|
1372
|
+
conf += "@completion_learning = #{@completion_learning}\n" unless @completion_learning
|
|
1373
|
+
conf.sub!(/^@completion_show_metadata.*(\n|$)/, "")
|
|
1374
|
+
conf += "@completion_show_metadata = #{@completion_show_metadata}\n" if @completion_show_metadata
|
|
1368
1375
|
conf.sub!(/^@plugin_disabled.*(\n|$)/, "")
|
|
1369
1376
|
conf += "@plugin_disabled = #{@plugin_disabled}\n" unless @plugin_disabled.empty?
|
|
1370
1377
|
conf.sub!(/^@validation_rules.*(\n|$)/, "")
|
|
1371
1378
|
conf += "@validation_rules = #{@validation_rules}\n" unless @validation_rules.empty?
|
|
1372
|
-
|
|
1373
|
-
conf
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1379
|
+
|
|
1380
|
+
File.write(Dir.home+'/.rshrc', conf)
|
|
1381
|
+
rshstate # Also save runtime state
|
|
1382
|
+
end
|
|
1383
|
+
def rshstate # Write runtime state to .rshstate (auto-managed, machine-specific)
|
|
1384
|
+
state = ""
|
|
1385
|
+
|
|
1386
|
+
# Runtime data that changes frequently
|
|
1387
|
+
state += "@cmd_frequency = #{@cmd_frequency}\n" unless @cmd_frequency.empty?
|
|
1388
|
+
state += "@cmd_stats = #{@cmd_stats}\n" unless @cmd_stats.empty?
|
|
1389
|
+
state += "@completion_weights = #{@completion_weights}\n" unless @completion_weights.empty?
|
|
1390
|
+
state += "@recordings = #{@recordings}\n" unless @recordings.empty?
|
|
1391
|
+
|
|
1378
1392
|
# Persist executable cache for faster startup
|
|
1379
1393
|
if @exe && @exe.length > 100
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
conf += "@exe_cache_time = #{Time.now.to_i}\n"
|
|
1386
|
-
end
|
|
1387
|
-
# Only write @cmd_completions if user has customized it
|
|
1388
|
-
unless conf =~ /^@cmd_completions\s*=/
|
|
1389
|
-
# Don't write default completions to avoid cluttering .rshrc
|
|
1390
|
-
end
|
|
1391
|
-
conf.sub!(/^@history.*(\n|$)/, "")
|
|
1394
|
+
state += "@exe_cache = #{@exe.inspect}\n"
|
|
1395
|
+
state += "@exe_cache_path = #{ENV['PATH'].inspect}\n"
|
|
1396
|
+
state += "@exe_cache_time = #{Time.now.to_i}\n"
|
|
1397
|
+
end
|
|
1398
|
+
|
|
1392
1399
|
# Ensure history is properly formatted as valid Ruby array
|
|
1393
1400
|
begin
|
|
1394
1401
|
history_str = @history.last(@histsize).inspect
|
|
1395
|
-
|
|
1402
|
+
state += "@history = #{history_str}\n"
|
|
1396
1403
|
rescue => e
|
|
1397
|
-
|
|
1398
|
-
puts "Warning: Error saving history: #{e.message}"
|
|
1404
|
+
state += "@history = []\n"
|
|
1405
|
+
puts "Warning: Error saving history: #{e.message}" if ENV['RSH_DEBUG']
|
|
1399
1406
|
end
|
|
1407
|
+
|
|
1408
|
+
File.write(Dir.home+'/.rshstate', state)
|
|
1409
|
+
end
|
|
1410
|
+
def migrate_to_split_config # Migrate from old single .rshrc to split .rshrc + .rshstate
|
|
1411
|
+
return if File.exist?(Dir.home+'/.rshstate') # Already migrated
|
|
1412
|
+
return unless File.exist?(Dir.home+'/.rshrc') # Nothing to migrate
|
|
1413
|
+
|
|
1414
|
+
puts "\nMigrating to split configuration (.rshrc + .rshstate)..."
|
|
1415
|
+
|
|
1416
|
+
# Runtime data will already be loaded from .rshrc by load_rshrc_safe
|
|
1417
|
+
# Just need to save it to .rshstate and clean .rshrc
|
|
1418
|
+
|
|
1419
|
+
# Create .rshstate with current runtime data
|
|
1420
|
+
rshstate
|
|
1421
|
+
|
|
1422
|
+
# Clean runtime data from .rshrc
|
|
1423
|
+
conf = File.read(Dir.home+'/.rshrc')
|
|
1424
|
+
conf.sub!(/^@cmd_frequency.*(\n|$)/, "")
|
|
1425
|
+
conf.sub!(/^@cmd_stats.*(\n|$)/, "")
|
|
1426
|
+
conf.sub!(/^@exe_cache.*(\n|$)/, "")
|
|
1427
|
+
conf.sub!(/^@exe_cache_path.*(\n|$)/, "")
|
|
1428
|
+
conf.sub!(/^@exe_cache_time.*(\n|$)/, "")
|
|
1429
|
+
conf.sub!(/^@completion_weights.*(\n|$)/, "")
|
|
1430
|
+
conf.sub!(/^@history =.*(\n|$)/, "")
|
|
1400
1431
|
File.write(Dir.home+'/.rshrc', conf)
|
|
1401
|
-
|
|
1432
|
+
|
|
1433
|
+
puts "Migration complete!"
|
|
1434
|
+
puts " .rshrc -> User config (portable)"
|
|
1435
|
+
puts " .rshstate -> Runtime data (auto-managed)\n"
|
|
1402
1436
|
end
|
|
1403
1437
|
|
|
1404
1438
|
# RSH FUNCTIONS
|
|
@@ -2973,6 +3007,15 @@ def load_rshrc_safe
|
|
|
2973
3007
|
end
|
|
2974
3008
|
end
|
|
2975
3009
|
|
|
3010
|
+
# Load runtime state from .rshstate (separate file)
|
|
3011
|
+
if File.exist?(Dir.home+'/.rshstate')
|
|
3012
|
+
begin
|
|
3013
|
+
load(Dir.home+'/.rshstate')
|
|
3014
|
+
rescue => e
|
|
3015
|
+
puts "Warning: Could not load .rshstate: #{e.message}" if ENV['RSH_DEBUG']
|
|
3016
|
+
end
|
|
3017
|
+
end
|
|
3018
|
+
|
|
2976
3019
|
rescue SyntaxError => e
|
|
2977
3020
|
puts "\n\033[31mERROR: Syntax error in .rshrc:\033[0m"
|
|
2978
3021
|
puts e.message
|
|
@@ -3169,6 +3212,7 @@ begin # Load .rshrc and populate @history
|
|
|
3169
3212
|
end
|
|
3170
3213
|
firstrun unless File.exist?(Dir.home+'/.rshrc') # Initial loading - to get history
|
|
3171
3214
|
load_rshrc_safe
|
|
3215
|
+
migrate_to_split_config # Migrate from old format if needed (v3.4.3+)
|
|
3172
3216
|
# Load login shell files if rsh is running as login shell
|
|
3173
3217
|
if ENV['LOGIN_SHELL'] or $0 == "-rsh" or ARGV.include?('-l') or ARGV.include?('--login')
|
|
3174
3218
|
['/etc/profile', Dir.home+'/.profile', Dir.home+'/.bash_profile', Dir.home+'/.bashrc'].each do |f|
|
|
@@ -3212,8 +3256,8 @@ end
|
|
|
3212
3256
|
# MAIN PART
|
|
3213
3257
|
loop do
|
|
3214
3258
|
begin
|
|
3215
|
-
@user
|
|
3216
|
-
@node
|
|
3259
|
+
@user ||= Etc.getpwuid(Process.euid).name # Cached for performance
|
|
3260
|
+
@node ||= Etc.uname[:nodename] # Cached for performance
|
|
3217
3261
|
# Only reload .rshrc if directory changed (optimization)
|
|
3218
3262
|
current_dir = Dir.pwd
|
|
3219
3263
|
if @last_prompt_dir != current_dir
|
|
@@ -3221,7 +3265,7 @@ loop do
|
|
|
3221
3265
|
@last_prompt_dir = current_dir
|
|
3222
3266
|
end
|
|
3223
3267
|
@prompt.gsub!(/#{Dir.home}/, '~') # Simplify path in prompt
|
|
3224
|
-
|
|
3268
|
+
print "\033]0;rsh: #{current_dir}\007" # Set window title (no spawn)
|
|
3225
3269
|
@history[0] = "" unless @history[0]
|
|
3226
3270
|
cache_executables # Use cached executable lookup
|
|
3227
3271
|
# Load plugins on first command (lazy loading)
|