Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
secretspecter | 5e4a8841ff | ||
secretspecter | b2e1ead4c7 | ||
secretspecter | 3aba831f2c | ||
secretspecter | 3bc3b43d3a | ||
secretspecter | 63f69fe22a | ||
secretspecter | d347d67671 | ||
secretspecter | 65d8492e4d |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Help/*
|
||||
Scripts/InstalledScriptInfos/*
|
|
@ -11,6 +11,17 @@ notepad "$(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
|
||||
|
||||
[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"
|
||||
}
|
||||
|
||||
if (-not $some_switch) {
|
||||
# a bang ! also works...
|
||||
}
|
||||
|
||||
$num = 0
|
||||
while ($num -lt 50) {
|
||||
$num = $num + 1
|
||||
}
|
||||
|
@ -59,10 +75,11 @@ There are [a lot of different powers](https://learn.microsoft.com/en-us/powershe
|
|||
|
||||
```powershell
|
||||
# Name-And-Age.ps1
|
||||
if ($silent) { exit }
|
||||
Write-Host "Hello $name"
|
||||
if ($age) {
|
||||
Write-Host "according to the -age you provided you are: $age"
|
||||
if (-not $silent) {
|
||||
Write-Host "Hello $name"
|
||||
if ($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"
|
||||
```
|
||||
|
||||
# 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 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)
|
||||
|
|
12
README.md
12
README.md
|
@ -10,6 +10,8 @@ Windows 11, at the time of writing, doesn't come with the latest PowerShell. It
|
|||
winget install --id Microsoft.Powershell --source winget
|
||||
```
|
||||
|
||||
- [ ] Install method that doesn't require git.
|
||||
|
||||
Then clone this repository to the desired `$PROFILE` sorta like this:
|
||||
|
||||
```powershell
|
||||
|
@ -55,17 +57,19 @@ I also added `Install-Scoop` and `Install-BleachBit` utility functions. They are
|
|||
|
||||
# `$env:PATH`
|
||||
|
||||
Folders in the semi-colon seperated `$env:PATH` string are searched for cmdlets, executables and scripts to run (again, if you're familiar with Bash it's similar to `$PATH`). Putting the following in `$PROFILE` will make custom `.ps1` scripts in that same folder "global" (available from any prompt without specifying the whole path).
|
||||
Folders in the semi-colon seperated `$env:PATH` string are searched for cmdlets, executables and scripts to run (again, if you're familiar with Bash it's similar to `$PATH`). Putting the following in `$PROFILE` will make `.ps1` files under the Scripts available globally (accessible from any terminal without specifying the whole path).
|
||||
|
||||
```powershell
|
||||
$env:PATH += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)"
|
||||
$env:PATH += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)\Scripts"
|
||||
```
|
||||
|
||||
[`Split-Path`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/split-path?view=powershell-7.3) is a pretty useful cmdlet for working with paths. Here we're saying "give me the parent folder for the current command path" which is the `$PROFILE` folder in this context. `$MyInvocation` is from the [automatic variables](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.3#myinvocation) which are provided by PowerShell under-the-hood.
|
||||
[`Split-Path`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/split-path?view=powershell-7.3) is a pretty useful cmdlet for working with paths. Here we're saying "give me the parent folder for the current command path" which is the `$PROFILE` folder in this context (and then we append ("\Scripts"). `$MyInvocation` is from the [automatic variables](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.3#myinvocation) which are provided by PowerShell under-the-hood.
|
||||
|
||||
## Update-And-Clean.ps1
|
||||
|
||||
With this I've also added a [`Update-And-Clean.ps1`](./Update-and-Clean.ps1) script (in the `$PROFILE` folder) that will update Windows as well as `scoop` if it's installed and then run `bleachbit --preset --clean` (also only if installed) **which depends on whatever you've last checked in the BleachBit UI... so run that and set it up first!** The script will also try to re-invoke itself as Administrator if you're not in an elevated session already... which is usually. If you're familiar with Arch Linux you might say `yay`!
|
||||
With this I've also added a [`Update-And-Clean.ps1`](./Update-and-Clean.ps1) script (in the `$PROFILE\Scripts` folder) that will update Windows as well as `scoop` if it's installed and then run `bleachbit --preset --clean` (also only if installed) **which depends on whatever you've last checked in the BleachBit UI... so run that and set it up first!** The script will also try to re-invoke itself as Administrator if you're not in an elevated session already... which is usually. If you're familiar with Arch Linux you might say `yay`!
|
||||
|
||||
- [ ] As admin: Set-ExecutionPolicy RemoteSigned or Unrestricted??
|
||||
|
||||
Checkout the [Crash Course](./CrashCourse.md) for a terse guide on writing your own PowerShell scripts.
|
||||
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
param(
|
||||
[string]$url = "",
|
||||
[system.io.fileinfo]$out = "~/Videos/Downloads/",
|
||||
[string]$out = "~/Videos/Downloads/",
|
||||
[string]$namepattern = "%(title)s",
|
||||
[int]$wait = 60 * 10
|
||||
)
|
||||
|
||||
if (!(Get-Command "yt-dlp.exe" -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "There's no yt-dlp.exe to work with!"
|
||||
if (-not (Get-Command "yt-dlp" -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "There's no yt-dlp to work with!"
|
||||
exit
|
||||
}
|
||||
|
||||
if (!(Test-Path $out -PathType container)) {
|
||||
if ($out -notmatch '\\$') {
|
||||
$out += "\"
|
||||
}
|
||||
|
||||
if (-not (Test-Path $out -PathType container)) {
|
||||
New-Item $out -ItemType container
|
||||
}
|
||||
|
||||
|
@ -24,7 +28,7 @@ if ($url) {
|
|||
else {
|
||||
while ($true) {
|
||||
$url = Read-host “URL”
|
||||
if (!$url) { break }
|
||||
if (-not $url) { break }
|
||||
Start-Process yt-dlp -ArgumentList "$ytdlp_options $url"
|
||||
}
|
||||
}
|
|
@ -5,18 +5,22 @@ param(
|
|||
$scale = 128
|
||||
)
|
||||
|
||||
if (!(Get-Command "magick.exe" -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "There's no magick.exe to work with!"
|
||||
if (-not (Get-Command "magick" -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "There's no magick to work with!"
|
||||
exit
|
||||
}
|
||||
|
||||
if ($in -notmatch '\\$') {
|
||||
$in += "\"
|
||||
}
|
||||
|
||||
if (Test-Path $in -PathType container) {
|
||||
$out_dir = "$out\x$scale\"
|
||||
if (!(Test-Path $out_dir)) {
|
||||
$out_dir = "$out\$(Split-Path -Leaf $in)_x$scale\"
|
||||
if (-not (Test-Path $out_dir)) {
|
||||
New-Item "$out_dir" -ItemType directory
|
||||
}
|
||||
foreach ($image in Get-ChildItem "$in*" -Include *.png) {
|
||||
$scaled = "$out_dir$($image.BaseName)$($image.Extension)"
|
||||
foreach ($image in Get-ChildItem "$in*" -Include *.png, *.jpg, *.gif) {
|
||||
$scaled = "$out_dir$($image.BaseName)_x$scale$($image.Extension)"
|
||||
Write-Host $scaled
|
||||
magick $image.FullName -scale "$($scale * 100)%" $scaled
|
||||
}
|
23
Scripts/Stream-Video.ps1
Normal file
23
Scripts/Stream-Video.ps1
Normal file
|
@ -0,0 +1,23 @@
|
|||
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 ($record -and -not $norecord) {
|
||||
$streamlink_opts += " --record $record"
|
||||
}
|
||||
|
||||
Write-Host "streamlink $streamlink_opts $url"
|
||||
Start-Process streamlink -ArgumentList "$streamlink_opts $url"
|
||||
}
|
23
Scripts/Stream.ps1
Normal file
23
Scripts/Stream.ps1
Normal file
|
@ -0,0 +1,23 @@
|
|||
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 ($record -and -not $norecord) {
|
||||
$streamlink_opts += " --record $record"
|
||||
}
|
||||
|
||||
Write-Host "streamlink $streamlink_opts $url"
|
||||
Start-Process streamlink -ArgumentList "$streamlink_opts $url"
|
||||
}
|
|
@ -1,13 +1,30 @@
|
|||
param([switch]$elevated)
|
||||
param(
|
||||
[switch]$elevated,
|
||||
[switch]$CleanOnly
|
||||
)
|
||||
|
||||
if (-not $CleanOnly -and -not $elevated) {
|
||||
winget upgrade --all --include-unknown
|
||||
}
|
||||
|
||||
if ((Get-Command "scoop" -ErrorAction SilentlyContinue) -and -not $elevated) {
|
||||
if (-not $CleanOnly) {
|
||||
scoop update
|
||||
scoop update --all
|
||||
scoop cleanup --al
|
||||
}
|
||||
scoop cache rm *
|
||||
}
|
||||
|
||||
# If not in an Administrator environment
|
||||
If (!(New-Object Security.Principal.WindowsPrincipal $(
|
||||
If (-not (New-Object Security.Principal.WindowsPrincipal $(
|
||||
[Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
)).IsInRole(
|
||||
[Security.Principal.WindowsBuiltinRole]::Administrator
|
||||
)
|
||||
) {
|
||||
# and elevating hasn't already been tried
|
||||
if (!$elevated) {
|
||||
if (-not $elevated) {
|
||||
# attempt to become Administrator by re-invoking this script
|
||||
Start-Process PowerShell -Verb RunAs -ArgumentList (
|
||||
'-file "{0}" -elevated' -f ($MyInvocation.MyCommand.Definition)
|
||||
|
@ -17,13 +34,15 @@ If (!(New-Object Security.Principal.WindowsPrincipal $(
|
|||
exit
|
||||
}
|
||||
|
||||
Get-WindowsUpdate -AcceptAll -Install
|
||||
if (Get-Command "scoop.exe" -ErrorAction SilentlyContinue) {
|
||||
scoop update
|
||||
scoop update --all
|
||||
scoop cache rm *
|
||||
|
||||
if (-not $CleanOnly) {
|
||||
if (-not (Get-Command "Get-WindowsUpdate")) {
|
||||
Install-Module PSWindowsUpdate
|
||||
}
|
||||
Get-WindowsUpdate -AcceptAll -Install
|
||||
}
|
||||
if (Get-Command "bleachbit.exe" -ErrorAction SilentlyContinue) {
|
||||
|
||||
if (Get-Command "bleachbit" -ErrorAction SilentlyContinue) {
|
||||
# Clean everything selected in the UI last time it was run.
|
||||
# So... run The UI to set things up initially.
|
||||
bleachbit --preset --clean
|
|
@ -1,5 +1,6 @@
|
|||
# Scripts in this $PROFILE folder are added to the PATH
|
||||
$env:PATH += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)"
|
||||
# Scripts in this $PROFILE\Scripts folder are added to the PATH
|
||||
$env:PATH += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)\Scripts"
|
||||
|
||||
|
||||
function prompt {
|
||||
$prompt = "> "
|
||||
|
@ -22,6 +23,9 @@ function Install-Scoop {
|
|||
}
|
||||
|
||||
function Install-BleachBit {
|
||||
if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) {
|
||||
scoop install git
|
||||
}
|
||||
scoop bucket add extras
|
||||
scoop install bleachbit
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue