chore: use script to register plugins in nushell

This commit is contained in:
Jesús Pérez 2025-09-20 20:14:02 +01:00
parent 187a69575c
commit 8dee8b776e

View File

@ -259,6 +259,9 @@ def main [
--plugins (-p): list<string> = [] # Specific plugins to install --plugins (-p): list<string> = [] # Specific plugins to install
--list (-l) # List available plugins --list (-l) # List available plugins
--dry-run (-d) # Show what would be done --dry-run (-d) # Show what would be done
--register-only (-r) # Only register plugins, don't copy binaries
--no-register # Copy binaries but don't register with nushell
--verify (-v) # Verify plugin registration after installation
] { ] {
let available_plugins = ls | where type == file and name =~ \"nu_plugin_\" | get name let available_plugins = ls | where type == file and name =~ \"nu_plugin_\" | get name
@ -281,24 +284,89 @@ def main [
return return
} }
print " + '$"🚀 Installing ($plugins_to_install | length) plugins to ($bin_path)..."' + " print " + '$"🚀 Processing ($plugins_to_install | length) plugins..."' + "
for plugin in " + '$plugins_to_install' + " { # Step 1: Copy binaries (unless register-only mode)
if " + '$dry_run' + " { if not " + '$register_only' + " {
print " + '$"Would install: ($plugin) → ($bin_path)/($plugin)"' + " print " + '$"\\n📦 Installing binaries to ($bin_path)..."' + "
} else { for plugin in " + '$plugins_to_install' + " {
try { if " + '$dry_run' + " {
cp " + '$plugin' + " " + '$"($bin_path)/($plugin)"' + " print " + '$"Would install: ($plugin) → ($bin_path)/($plugin)"' + "
chmod +x " + '$"($bin_path)/($plugin)"' + " } else {
print " + '$" ✅ Installed ($plugin)"' + " try {
} catch {|err| cp " + '$plugin' + " " + '$"($bin_path)/($plugin)"' + "
print " + '$" ❌ Failed to install ($plugin): ($err.msg)"' + " chmod +x " + '$"($bin_path)/($plugin)"' + "
print " + '$" ✅ Installed ($plugin)"' + "
} catch {|err|
print " + '$" ❌ Failed to install ($plugin): ($err.msg)"' + "
}
} }
} }
} }
# Step 2: Register plugins with nushell (unless disabled)
if not " + '$no_register' + " {
print \"\\n🔌 Registering plugins with nushell...\"
for plugin in " + '$plugins_to_install' + " {
let plugin_path = if " + '$register_only' + " {
# Use current directory path for register-only mode
" + '$"./($plugin)"' + "
} else {
# Use installation path for normal mode
" + '$"($bin_path)/($plugin)"' + "
}
if " + '$dry_run' + " {
print " + '$"Would register: plugin add ($plugin_path)"' + "
} else {
try {
nu -c " + '$"plugin add ($plugin_path)"' + "
print " + '$" ✅ Registered ($plugin)"' + "
} catch {|err|
print " + '$" ⚠️ Failed to register ($plugin): ($err.msg)"' + "
print " + '$" You can manually register with: plugin add ($plugin_path)"' + "
}
}
}
}
# Step 3: Verify plugin registration (if requested and plugins were registered)
if " + '$verify' + " and not " + '$no_register' + " and not " + '$dry_run' + " {
print \"\\n🔍 Verifying plugin registration...\"
for plugin in " + '$plugins_to_install' + " {
let plugin_name = (" + '$plugin' + " | str replace \"nu_plugin_\" \"\")
try {
let found = (nu -c " + '$"plugin list | where name =~ ($plugin_name) | length"' + " | into int)
if " + '$found' + " > 0 {
print " + '$" ✅ Verified ($plugin)"' + "
} else {
print " + '$" ❌ Not found in plugin list: ($plugin)"' + "
}
} catch {|err|
print " + '$" ⚠️ Could not verify ($plugin): ($err.msg)"' + "
}
}
}
# Summary
if not " + '$dry_run' + " { if not " + '$dry_run' + " {
print \"\\n💡 Don't forget to run 'plugin add' for each plugin in nushell!\" if " + '$register_only' + " {
print \"\\n✅ Plugin registration completed!\"
if " + '$verify' + " {
print \"💡 Run 'plugin list' to see all registered plugins\"
}
} else if " + '$no_register' + " {
print \"\\n✅ Plugin installation completed!\"
print \"💡 To register plugins, run: nu install_nu_plugins.nu --register-only\"
} else {
print \"\\n✅ Plugin installation and registration completed!\"
if " + '$verify' + " {
print \"💡 All plugins verified. Run 'plugin list' to see details\"
} else {
print \"💡 Restart nushell or run 'plugin list' to see registered plugins\"
print \" Add --verify to automatically check registration next time\"
}
}
} }
} }
" "