Last active
May 5, 2024 14:44
-
-
Save melMass/f54a0ee7f1ab0f255fb4022ab3cd239b to your computer and use it in GitHub Desktop.
Powershell script to update nushell and its plugins.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Creates a new directory if it doesn't exist. | |
.DESCRIPTION | |
The New-Directory function creates a new directory at the specified path | |
if it doesn't already exist. | |
.PARAMETER Path | |
Specifies the path of the directory to create. | |
.EXAMPLE | |
New-Directory -Path "~/dev/nushell" | |
This command creates a new directory named "nushell" in the "~/dev" directory. | |
#> | |
function New-Directory | |
{ | |
param ( | |
[string]$Path | |
) | |
$splitPath = $Path -split "\\" | |
$currentPath = "" | |
foreach ($folder in $splitPath) | |
{ | |
$currentPath += "$folder\" | |
if (-not (Test-Path -Path $currentPath)) | |
{ | |
New-Item -ItemType Directory -Path $currentPath | Out-Null | |
} | |
} | |
} | |
<# | |
.SYNOPSIS | |
Checks if a directory exists, clones it if not, and changes to it. | |
.DESCRIPTION | |
The Clone-OrCdToDirectory function checks if the specified directory exists. | |
If it doesn't exist, it clones it from the specified repository URL and changes | |
the current directory to it. If it does exist, it changes to it and updates | |
the repository if necessary. | |
.PARAMETER Path | |
Specifies the path of the directory to check or clone. | |
.PARAMETER RepositoryURL | |
Specifies the URL of the repository to clone from if the directory doesn't exist. | |
.EXAMPLE | |
Clone-OrCdToDirectory -Path "nushell" -RepositoryURL "https://github.com/nushell/nushell.git" | |
This command checks if the "nushell" directory exists. If it doesn't, it clones the | |
repository from the specified URL. If it does exist, it changes to the directory | |
and updates the repository. | |
#> | |
function Clone-OrCdToDirectory | |
{ | |
param ( | |
[string]$Path, | |
[string]$RepositoryURL | |
) | |
if (-not (Test-Path -Path $Path)) | |
{ | |
git clone --recursive $RepositoryURL $Path | |
Set-Location -Path $Path | |
} else | |
{ | |
Set-Location -Path $Path | |
git fetch | |
git pull | |
} | |
} | |
# mkdir -p equivalent | |
New-Directory -Path "~/dev/nushell" | |
Set-Location -Path "~/dev/nushell" | |
Clone-OrCdToDirectory -Path "nushell" -RepositoryURL "https://github.com/nushell/nushell.git" | |
# Install nushell | |
cargo install --path . --features plugin,sqlite | |
# Install core plugins | |
Set-Location -Path "crates/nu_plugin_query" | |
cargo install --path . | |
# plugin add "~/.cargo/bin/nu_plugin_query" | |
Set-Location -Path "../nu_plugin_formats" | |
cargo install --path . | |
# plugin add "~/.cargo/bin/nu_plugin_formats" | |
Set-Location -Path "../nu_plugin_gstat" | |
cargo install --path . | |
# plugin add "~/.cargo/bin/nu_plugin_gstat" | |
Set-Location -Path "../nu_plugin_polars" | |
cargo install --path . | |
# plugin add "~/.cargo/bin/nu_plugin_polars" | |
# Extra plugins | |
New-Directory -Path "~/dev/nushell/third_party_plugins" | |
Set-Location -Path "~/dev/nushell/third_party_plugins" | |
Clone-OrCdToDirectory -Path "nu_plugin_desktop_notifications" -RepositoryURL "https://github.com/FMotalleb/nu_plugin_desktop_notifications.git" | |
cargo install --path . | |
Set-Location -Path "~/dev/nushell/third_party_plugins" | |
Clone-OrCdToDirectory -Path "nu_plugin_dns" -RepositoryURL "https://github.com/dead10ck/nu_plugin_dns.git" | |
cargo +nightly install --path . | |
Write-Output "Please run the following commands within NuShell:" | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_query"' | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_formats"' | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_gstat"' | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_polars"' | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_desktop_notifications"' | |
Write-Output 'plugin add "~/.cargo/bin/nu_plugin_dns"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment