diff --git a/README.md b/README.md index 8601202..1515d1c 100644 --- a/README.md +++ b/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. diff --git a/Download-Video.ps1 b/Scripts/Download-Video.ps1 similarity index 88% rename from Download-Video.ps1 rename to Scripts/Download-Video.ps1 index 77d8ece..c38355e 100644 --- a/Download-Video.ps1 +++ b/Scripts/Download-Video.ps1 @@ -1,6 +1,6 @@ param( [string]$url = "", - [system.io.fileinfo]$out = "~/Videos/Downloads/", + [string]$out = "~/Videos/Downloads/", [string]$namepattern = "%(title)s", [int]$wait = 60 * 10 ) @@ -10,6 +10,10 @@ if (!(Get-Command "yt-dlp.exe" -ErrorAction SilentlyContinue)) { exit } +if ($out -notmatch '\\$') { + $out += "\" +} + if (!(Test-Path $out -PathType container)) { New-Item $out -ItemType container } diff --git a/Pixel-Scale.ps1 b/Scripts/Scale-Pixel.ps1 similarity index 90% rename from Pixel-Scale.ps1 rename to Scripts/Scale-Pixel.ps1 index 905fead..b7b38ee 100644 --- a/Pixel-Scale.ps1 +++ b/Scripts/Scale-Pixel.ps1 @@ -15,7 +15,7 @@ if (Test-Path $in -PathType container) { if (!(Test-Path $out_dir)) { New-Item "$out_dir" -ItemType directory } - foreach ($image in Get-ChildItem "$in*" -Include *.png) { + foreach ($image in Get-ChildItem "$in*" -Include *.png, *.jpg, *.gif) { $scaled = "$out_dir$($image.BaseName)$($image.Extension)" Write-Host $scaled magick $image.FullName -scale "$($scale * 100)%" $scaled diff --git a/Update-And-Clean.ps1 b/Scripts/Update-And-Clean.ps1 similarity index 92% rename from Update-And-Clean.ps1 rename to Scripts/Update-And-Clean.ps1 index fa94127..bf88943 100644 --- a/Update-And-Clean.ps1 +++ b/Scripts/Update-And-Clean.ps1 @@ -17,6 +17,10 @@ If (!(New-Object Security.Principal.WindowsPrincipal $( exit } +if (!(Get-Module PSWindowsUpdate)) { + Install-Module PSWindowsUpdate +} + Get-WindowsUpdate -AcceptAll -Install if (Get-Command "scoop.exe" -ErrorAction SilentlyContinue) { scoop update diff --git a/profile.ps1 b/profile.ps1 index ec334d4..380817f 100644 --- a/profile.ps1 +++ b/profile.ps1 @@ -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 (!(Get-Command "git.exe" -ErrorAction SilentlyContinue)) { + scoop install git + } scoop bucket add extras scoop install bleachbit }