From d1075e3cdb391d38081cee84520f0f52ad919132 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 28 Dec 2022 14:31:08 +0100 Subject: [PATCH] Add cd-trash.ps1 --- Scripts/cd-recycle-bin.ps1 | 6 +++++- Scripts/cd-trash.ps1 | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 Scripts/cd-trash.ps1 diff --git a/Scripts/cd-recycle-bin.ps1 b/Scripts/cd-recycle-bin.ps1 index 52df86a0..eb226657 100755 --- a/Scripts/cd-recycle-bin.ps1 +++ b/Scripts/cd-recycle-bin.ps1 @@ -19,7 +19,11 @@ function GetCurrentUserSID { [CmdletBinding()] param() try { - $Path = 'C:\$Recycle.Bin\' + "$(GetCurrentUserSID)" + if ($IsLinux) { + $Path = "$HOME/.local/share/Trash/" + } else { + $Path = "C:\$Recycle.Bin\" + "$(GetCurrentUserSID)" + } if (-not(Test-Path "$Path" -pathType container)) { throw "Recycle bin folder at 📂$Path doesn't exist (yet)" } diff --git a/Scripts/cd-trash.ps1 b/Scripts/cd-trash.ps1 new file mode 100755 index 00000000..c8f45a84 --- /dev/null +++ b/Scripts/cd-trash.ps1 @@ -0,0 +1,36 @@ +<# +.SYNOPSIS + Sets the working directory to the user's trash folder +.DESCRIPTION + This PowerShell script changes the working directory to the user's trash folder. +.EXAMPLE + PS> ./cd-trash + 📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +function GetCurrentUserSID { [CmdletBinding()] param() + Add-Type -AssemblyName System.DirectoryServices.AccountManagement + return ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value +} + + +try { + if ($IsLinux) { + $Path = "$HOME/.local/share/Trash/" + } else { + $Path = "C:\$Recycle.Bin\" + "$(GetCurrentUserSID)" + } + if (-not(Test-Path "$Path" -pathType container)) { + throw "Trash folder at 📂$Path doesn't exist (yet)" + } + Set-Location "$Path" + "📂$Path" + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}