Something went wrong. Try again.
Easily turn Nushell modules into cross-shell CLI tools
library nu nushell
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374# SPDX-License-Identifier: AGPL-3.0-only# Copyright (c) 2026 MatrixFurry <matrix@matrixfurry.com>
const template: path = path self ./template.nu
export def install [ src: path # Module source path prefix?: path = ~/.local # installation prefix --force (-f) # Overwrite existing files --install-module (-i) # Install module in Nushell library directory --bin-name (-b): string # Override final binary name --module-name (-m): string # Override module name --print-usage # [EXPERIMENTAL] Print command usage when executing --help or --list] { let src = $src | path expand let prefix = $prefix | path expand let mod_name = $module_name | default ($src | path basename) let installed_mod_path = $prefix | path join "share" $mod_name "module" $mod_name let bin_name = $bin_name | default $mod_name let installed_bin_path = $prefix | path join "bin" $bin_name
if $force { rm -rf $installed_mod_path rm -f $installed_bin_path } else if ($installed_mod_path | path exists) or ($installed_bin_path | path exists) { error make -u { msg: "It looks like this tool is already installed, or there are conflicting files installed" help: "If you're attempting to update or re-install the tool, use --force" } }
# Module mkdir ($installed_mod_path | path dirname) cp -r $src $installed_mod_path
if $install_module { let nu_lib_dir = $env.NU_LIB_DIRS | first if $force {rm -f ($nu_lib_dir | path join $mod_name)} ln -s $installed_mod_path $nu_lib_dir }
# Create & install binary mkdir ($installed_bin_path | path dirname)
open $template --raw | str replace "@MODULE_PATH@" $installed_mod_path | str replace "@PRINT_USAGE@" ($print_usage | into string) | save --progress $installed_bin_path
chmod +x $installed_bin_path}
export def uninstall [ name: string # CLI tool to uninstall prefix?: path = ~/.local # installation prefix --bin-name (-b): string # Override binary name --remove-module (-m) # Remove module in Nushell library directory] { let prefix = $prefix | path expand let mod_name = $name let installed_mod_path = $prefix | path join "share" $mod_name "module" $mod_name let bin_name = $bin_name | default $name let installed_bin_path = $prefix | path join "bin" $bin_name
rm -rf $installed_mod_path rm -f $installed_bin_path
if $remove_module { let nu_lib_dir = $env.NU_LIB_DIRS | first rm -f ($nu_lib_dir | path join $mod_name) }}