mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-08-23 22:16:48 +00:00
feat: add pwsh-essentials
This commit is contained in:
@@ -39,6 +39,7 @@ __init_powershell() {
|
||||
|
||||
pkg_done_message() {
|
||||
echo "Installed 'pwsh' at $pkg_dst"
|
||||
pwsh -V
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: pwsh-essentials
|
||||
homepage: https://webinstall.dev/pwsh-essentials
|
||||
tagline: |
|
||||
meta package for our recommended PowerShell plugins and settings
|
||||
---
|
||||
|
||||
To update (replacing the current version) run `webi pwsh-essentials`.
|
||||
|
||||
## Cheat Sheet
|
||||
|
||||
> The tools you need to write PowerShell effectively.
|
||||
|
||||
This meta package will install the full set of plugins and settings we
|
||||
recommended.
|
||||
|
||||
### Files
|
||||
|
||||
These are the files / directories that are created and/or modified with this
|
||||
install:
|
||||
|
||||
```text
|
||||
~/.config/envman/PATH.env
|
||||
~/.local/bin/pwsh-fix.ps1
|
||||
~/.local/bin/pwsh-fmt.ps1
|
||||
~/.local/bin/pwsh-lint.ps1
|
||||
~/.local/opt/pwsh/
|
||||
~/.local/share/powershell/Modules/PSScriptAnalyzer/
|
||||
```
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
$PkgName = "pwsh-essentials"
|
||||
|
||||
function Repair-MissingCommand {
|
||||
Param(
|
||||
[string]$Name,
|
||||
[string]$Package,
|
||||
[string]$Command
|
||||
)
|
||||
|
||||
Write-Host " Checking for $Name ..."
|
||||
$HasCommand = Get-Command -Name $Command -ErrorAction Silent
|
||||
IF ($HasCommand) {
|
||||
Return
|
||||
}
|
||||
|
||||
& $HOME\.local\bin\webi-pwsh.ps1 $Package
|
||||
$null = Sync-EnvPath
|
||||
}
|
||||
|
||||
function Install-WebiHostedPSCoreScript () {
|
||||
Param(
|
||||
[string]$Package,
|
||||
[string]$ScriptName
|
||||
)
|
||||
$PwshName = "_${ScriptName}.ps1"
|
||||
$PwshUrl = "${Env:WEBI_HOST}/packages/${Package}/${ScriptName}.ps1"
|
||||
$PwshPath = "$HOME\.local\bin\${PwshName}"
|
||||
$OldPath = "$HOME\.local\bin\${ScriptName}.ps1"
|
||||
|
||||
$BatPath = "$HOME\.local\bin\${ScriptName}.bat"
|
||||
$PwshExec = "pwsh -ExecutionPolicy Bypass"
|
||||
$Bat = "@echo off`r`n$PwshExec %USERPROFILE%\.local\bin\${PwshName} %*"
|
||||
|
||||
Invoke-DownloadUrl -Force -URL $PwshUrl -Path $PwshPath
|
||||
Set-Content -Path $BatPath -Value $Bat
|
||||
Write-Host " Created alias ${BatPath}"
|
||||
Write-Host " to run ${PwshPath}"
|
||||
|
||||
# fix for old installs
|
||||
Remove-Item -Path $OldPath -Force -ErrorAction Ignore
|
||||
}
|
||||
|
||||
function Install-PwshEssential {
|
||||
# Fetch PowerShell Core
|
||||
Repair-MissingCommand -Name "PowerShell Core" -Package "pwsh" -Command "pwsh"
|
||||
|
||||
# Fetch PSScriptAnalyzer (fmt, lint, fix)
|
||||
& $HOME\.local\bin\webi-pwsh.ps1 psscriptanalyzer
|
||||
|
||||
# Fetch shorthand commands to fmt, lint, & fix
|
||||
$ScriptNames = , "pwsh-fmt", "pwsh-fix", "pwsh-lint"
|
||||
foreach ($ScriptName in $ScriptNames) {
|
||||
Write-Host ""
|
||||
Write-Host "${TTask}Installing${TReset} ${TName}$ScriptName${TReset}"
|
||||
Install-WebiHostedPSCoreScript -Package $PkgName -ScriptName $ScriptName
|
||||
}
|
||||
|
||||
$PwshRunUrl = "${Env:WEBI_HOST}/packages/${PkgName}/pwsh-run.bat"
|
||||
$PwshRunPath = "$HOME\.local\bin\pwsh-run.bat"
|
||||
Invoke-DownloadUrl -Force -URL $PwshRunUrl -Path $PwshRunPath
|
||||
}
|
||||
|
||||
Install-PwshEssential
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
set -u
|
||||
|
||||
__run_pwsh_essentials() {
|
||||
# PowerShell Core
|
||||
if ! command -v pwsh > /dev/null; then
|
||||
"$HOME/.local/bin/webi" "pwsh@${WEBI_TAG}"
|
||||
fi
|
||||
export PATH="$HOME/.local/opt/pwsh:$PATH"
|
||||
|
||||
# PSScriptAnalyzer (Linter, Fixer, & Formatter)
|
||||
"$HOME/.local/bin/webi" "psscriptanalyzer"
|
||||
|
||||
# pwsh-fmt, pwsh-fix, pwsh-lint
|
||||
for b_file in pwsh-fmt.ps1 pwsh-fix.ps1 pwsh-lint.ps1; do
|
||||
rm -f ~/.local/bin/"${b_file}"
|
||||
webi_download \
|
||||
"${WEBI_HOST}/packages/${PKG_NAME}/${b_file}" \
|
||||
~/.local/bin/"${b_file}" \
|
||||
"${b_file}"
|
||||
chmod a+x ~/.local/bin/"${b_file}"
|
||||
~/.local/bin/"${b_file}" ~/.local/bin/"${b_file}"
|
||||
done
|
||||
echo ""
|
||||
}
|
||||
|
||||
__run_pwsh_essentials
|
||||
Reference in New Issue
Block a user