updates and improvements
This commit is contained in:
parent
d347d67671
commit
63f69fe22a
|
@ -11,6 +11,17 @@ notepad "$(Split-Path -Parent $PROFILE.CurrentUserAllHosts)\my-script.ps1"
|
||||||
codium "$(Split-Path -Parent $PROFILE.CurrentUserAllHosts)\my-script.ps1"
|
codium "$(Split-Path -Parent $PROFILE.CurrentUserAllHosts)\my-script.ps1"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Get-Help
|
||||||
|
|
||||||
|
You can learn about pretty much anything in PowerShell with the `Get-Help` cmdlet.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Update-Help
|
||||||
|
Get-Help Get-Help
|
||||||
|
Get-Help New-Item
|
||||||
|
Get-Help Get-ChildItem
|
||||||
|
```
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
|
|
||||||
[PowerShell is as case-insensitive as possible.](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_case-sensitivity?view=powershell-7.3) This means `$MyInvocation` works just the same as `$mYinVoCAtiOn` among other things. Coming from a Unix background and preferring some consistency I like to pretend it is case-sensitive so in this repo I'll strive for that but it's worth keeping in mind. Especially since **the Microsoft docs use case a lot** in variable and cmdlet names.
|
[PowerShell is as case-insensitive as possible.](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_case-sensitivity?view=powershell-7.3) This means `$MyInvocation` works just the same as `$mYinVoCAtiOn` among other things. Coming from a Unix background and preferring some consistency I like to pretend it is case-sensitive so in this repo I'll strive for that but it's worth keeping in mind. Especially since **the Microsoft docs use case a lot** in variable and cmdlet names.
|
||||||
|
@ -38,6 +49,11 @@ else {
|
||||||
Write-Host "value is not a y"
|
Write-Host "value is not a y"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-not $some_switch) {
|
||||||
|
# a bang ! also works...
|
||||||
|
}
|
||||||
|
|
||||||
|
$num = 0
|
||||||
while ($num -lt 50) {
|
while ($num -lt 50) {
|
||||||
$num = $num + 1
|
$num = $num + 1
|
||||||
}
|
}
|
||||||
|
@ -59,10 +75,11 @@ There are [a lot of different powers](https://learn.microsoft.com/en-us/powershe
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
# Name-And-Age.ps1
|
# Name-And-Age.ps1
|
||||||
if ($silent) { exit }
|
if (-not $silent) {
|
||||||
Write-Host "Hello $name"
|
Write-Host "Hello $name"
|
||||||
if ($age) {
|
if ($age) {
|
||||||
Write-Host "according to the -age you provided you are: $age"
|
Write-Host "according to the -age you provided you are: $age"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -74,16 +91,6 @@ Name-And-Age.ps1 -name "Rose" -age "27"
|
||||||
Name-And-Age.ps1 "Rose" "27"
|
Name-And-Age.ps1 "Rose" "27"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Get-Help
|
|
||||||
|
|
||||||
You can learn about the available `param` list for pretty much anything in PowerShell with the `Get-Help` cmdlet.
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
Get-Help Get-Help
|
|
||||||
Get-Help New-Item
|
|
||||||
Get-Help Name-And-Age.ps1
|
|
||||||
```
|
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
|
|
||||||
Functions use `param` too (instead of parenthesis like other languages). The last value is the `return` result, (which you can also use to `return` early... or just regularly if you want)
|
Functions use `param` too (instead of parenthesis like other languages). The last value is the `return` result, (which you can also use to `return` early... or just regularly if you want)
|
||||||
|
|
|
@ -5,8 +5,8 @@ param(
|
||||||
[int]$wait = 60 * 10
|
[int]$wait = 60 * 10
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!(Get-Command "yt-dlp.exe" -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command "yt-dlp" -ErrorAction SilentlyContinue)) {
|
||||||
Write-Host "There's no yt-dlp.exe to work with!"
|
Write-Host "There's no yt-dlp to work with!"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ if ($out -notmatch '\\$') {
|
||||||
$out += "\"
|
$out += "\"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(Test-Path $out -PathType container)) {
|
if (-not (Test-Path $out -PathType container)) {
|
||||||
New-Item $out -ItemType container
|
New-Item $out -ItemType container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ if ($url) {
|
||||||
else {
|
else {
|
||||||
while ($true) {
|
while ($true) {
|
||||||
$url = Read-host “URL”
|
$url = Read-host “URL”
|
||||||
if (!$url) { break }
|
if (-not $url) { break }
|
||||||
Start-Process yt-dlp -ArgumentList "$ytdlp_options $url"
|
Start-Process yt-dlp -ArgumentList "$ytdlp_options $url"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ param(
|
||||||
$scale = 128
|
$scale = 128
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!(Get-Command "magick.exe" -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command "magick" -ErrorAction SilentlyContinue)) {
|
||||||
Write-Host "There's no magick.exe to work with!"
|
Write-Host "There's no magick to work with!"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Test-Path $in -PathType container) {
|
if (Test-Path $in -PathType container) {
|
||||||
$out_dir = "$out\x$scale\"
|
$out_dir = "$out\x$scale\"
|
||||||
if (!(Test-Path $out_dir)) {
|
if (-not (Test-Path $out_dir)) {
|
||||||
New-Item "$out_dir" -ItemType directory
|
New-Item "$out_dir" -ItemType directory
|
||||||
}
|
}
|
||||||
foreach ($image in Get-ChildItem "$in*" -Include *.png, *.jpg, *.gif) {
|
foreach ($image in Get-ChildItem "$in*" -Include *.png, *.jpg, *.gif) {
|
||||||
|
|
22
Scripts/Stream.ps1
Normal file
22
Scripts/Stream.ps1
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
param(
|
||||||
|
[string]$url = "",
|
||||||
|
[string]$record = "~/Videos/Streamed/{title}.ts",
|
||||||
|
[int]$retryinterval = 30,
|
||||||
|
[string]$quality = "best",
|
||||||
|
[switch]$norecord
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($url) {
|
||||||
|
if (-not (Get-Command "streamlink" -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Host "There's no streamlink to work with!"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
$streamlink_opts = "--default-stream $quality"
|
||||||
|
$streamlink_opts = " --retry-streams $retryinterval"
|
||||||
|
if ($out -and -not $norecord) {
|
||||||
|
$streamlink_opts = " --record $out"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Process streamlink -ArgumentList "$streamlink_opts $url"
|
||||||
|
}
|
|
@ -1,13 +1,25 @@
|
||||||
param([switch]$elevated)
|
param(
|
||||||
|
[switch]$elevated,
|
||||||
|
[switch]$CleanOnly
|
||||||
|
)
|
||||||
|
|
||||||
|
if ((Get-Command "scoop" -ErrorAction SilentlyContinue) -and -not $elevated) {
|
||||||
|
if (-not $CleanOnly) {
|
||||||
|
scoop update
|
||||||
|
scoop update --all
|
||||||
|
}
|
||||||
|
scoop cache rm *
|
||||||
|
}
|
||||||
|
|
||||||
# If not in an Administrator environment
|
# If not in an Administrator environment
|
||||||
If (!(New-Object Security.Principal.WindowsPrincipal $(
|
If (-not (New-Object Security.Principal.WindowsPrincipal $(
|
||||||
[Security.Principal.WindowsIdentity]::GetCurrent()
|
[Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
)).IsInRole(
|
)).IsInRole(
|
||||||
[Security.Principal.WindowsBuiltinRole]::Administrator
|
[Security.Principal.WindowsBuiltinRole]::Administrator
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
# and elevating hasn't already been tried
|
# and elevating hasn't already been tried
|
||||||
if (!$elevated) {
|
if (-not $elevated) {
|
||||||
# attempt to become Administrator by re-invoking this script
|
# attempt to become Administrator by re-invoking this script
|
||||||
Start-Process PowerShell -Verb RunAs -ArgumentList (
|
Start-Process PowerShell -Verb RunAs -ArgumentList (
|
||||||
'-file "{0}" -elevated' -f ($MyInvocation.MyCommand.Definition)
|
'-file "{0}" -elevated' -f ($MyInvocation.MyCommand.Definition)
|
||||||
|
@ -17,17 +29,15 @@ If (!(New-Object Security.Principal.WindowsPrincipal $(
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(Get-Module PSWindowsUpdate)) {
|
|
||||||
Install-Module PSWindowsUpdate
|
if (-not $CleanOnly) {
|
||||||
|
if (-not (Get-Command "Get-WindowsUpdate")) {
|
||||||
|
Install-Module PSWindowsUpdate
|
||||||
|
}
|
||||||
|
Get-WindowsUpdate -AcceptAll -Install
|
||||||
}
|
}
|
||||||
|
|
||||||
Get-WindowsUpdate -AcceptAll -Install
|
if (Get-Command "bleachbit" -ErrorAction SilentlyContinue) {
|
||||||
if (Get-Command "scoop.exe" -ErrorAction SilentlyContinue) {
|
|
||||||
scoop update
|
|
||||||
scoop update --all
|
|
||||||
scoop cache rm *
|
|
||||||
}
|
|
||||||
if (Get-Command "bleachbit.exe" -ErrorAction SilentlyContinue) {
|
|
||||||
# Clean everything selected in the UI last time it was run.
|
# Clean everything selected in the UI last time it was run.
|
||||||
# So... run The UI to set things up initially.
|
# So... run The UI to set things up initially.
|
||||||
bleachbit --preset --clean
|
bleachbit --preset --clean
|
||||||
|
|
|
@ -23,7 +23,7 @@ function Install-Scoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Install-BleachBit {
|
function Install-BleachBit {
|
||||||
if (!(Get-Command "git.exe" -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) {
|
||||||
scoop install git
|
scoop install git
|
||||||
}
|
}
|
||||||
scoop bucket add extras
|
scoop bucket add extras
|
||||||
|
|
Loading…
Reference in a new issue