Updated the cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz
2025-07-09 14:19:53 +02:00
parent d3e77308a8
commit 51b541e0de
30 changed files with 115 additions and 65 deletions

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "~/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
if (-not(Test-Path "$path" -pathType container)) {

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) { throw "Sorry, Windows only" }

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux -or $IsMacOS) {
if (-not(Test-Path "~/Desktop" -pathType container)) {

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (-not(Test-Path "~/Dropbox" -pathType container)) {
throw "No 'Dropbox' folder in your home directory - is Dropbox installed?"

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux -or $IsMacOS) {
$path = "/etc"

View File

@ -4,7 +4,7 @@
.DESCRIPTION
This PowerShell script changes the working directory to the Jenkins home directory.
.EXAMPLE
PS> ./cd-jenkins
PS> ./cd-jenkins.ps1
📂C:\Users\Markus\.jenkins entered (has 2 files and 21 folders)
.LINK
https://github.com/fleschutz/PowerShell
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (Test-Path "~/.jenkins" -pathType container) {
$path = "~/.jenkins"

View File

@ -4,14 +4,16 @@
.DESCRIPTION
This PowerShell script changes the current working directory to the logs directory.
.EXAMPLE
PS> ./cd-logs
📂/var/logs entered (has 3 files and 2 subfolders)
PS> ./cd-logs.ps1
📂/var/logs with 3 files and 2 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
function GetLogsDir {
if ($IsLinux -or $IsMacOS) { return "/var/logs" }
$WinDir = [System.Environment]::GetFolderPath('Windows')
@ -23,9 +25,9 @@ try {
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) {
if (-not(Test-Path "~/Music/" -pathType container)) {
@ -30,6 +32,6 @@ try {
"📂$path with $($folders.Count) folders and $($files.Count) files entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -4,14 +4,16 @@
.DESCRIPTION
This PowerShell script changes the working directory to the user's NextCloud folder.
.EXAMPLE
PS> ./cd-nextcloud
📂C:\Users\Markus\NextCloud entered (has 2 files and 0 folders)
PS> ./cd-nextcloud.ps1
📂C:\Users\Markus\NextCloud with 2 files and 0 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (-not(Test-Path "~/NextCloud" -pathType container)) {
throw "No 'NextCloud' folder in your home directory - is NextCloud installed?"
@ -20,9 +22,9 @@ try {
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (-not(Test-Path "~/OneDrive" -pathType container)) {
throw "No 'OneDrive' folder in your home directory - is OneDrive installed?"
@ -23,6 +25,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working dir to the user's pictures folder
.DESCRIPTION
This PowerShell script sets the current working directory to the user's pictures folder.
This PowerShell script changes the current working directory to the user's pictures folder.
.EXAMPLE
PS> ./cd-pics.ps1
📂C:\Users\Markus\Pictures with 7 files and 0 folders entered.
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) {
if (-not(Test-Path "~/Pictures" -pathType container)) {
@ -30,6 +32,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working dir to the Public folder
.DESCRIPTION
This PowerShell script sets the current working directory to the Public folder.
This PowerShell script changes the current working directory to the Public folder.
.EXAMPLE
PS> ./cd-public.ps1
📂C:\Users\Public with 2 files and 3 folders entered.
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) {
if (-not(Test-Path "~/Public" -pathType container)) {
@ -30,6 +32,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,27 +2,28 @@
.SYNOPSIS
Sets the working directory to the 'recent' folder
.DESCRIPTION
This PowerShell script changes the working directory to the 'recent' folder.
This PowerShell script changes the current working directory to the 'recent' folder.
.EXAMPLE
PS> ./cd-recent
📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent entered (has 2 files and 3 subfolders)
PS> ./cd-recent.ps1
📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent with 2 files and 3 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = [Environment]::GetFolderPath('Recent')
if (-not(Test-Path "$path" -pathType container)) {
throw "No recent folder at $path"
}
if (-not(Test-Path "$path" -pathType container)) { throw "No recent folder at $path" }
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working dir to the recycle bin folder
.DESCRIPTION
This PowerShell script changes the working directory to the user's recycle bin folder.
This PowerShell script changes the current working directory to the user's recycle bin folder.
.EXAMPLE
PS> ./cd-recycle-bin.ps1
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 with 2 files and 0 folders entered.
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
function GetCurrentUserSID { [CmdletBinding()] param()
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
return ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value
@ -33,6 +35,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working directory to a repo
.DESCRIPTION
This PowerShell script changes the working directory to the given local Git repository.
This PowerShell script changes the current working directory to the given local Git repository.
.PARAMETER folderName
Specifies the folder name of the Git repository
.EXAMPLE
@ -43,6 +43,6 @@ try {
& git status --branch --short
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working dir to the repos folder
.DESCRIPTION
This PowerShell script changes the working directory to the folder for Git repositories.
This PowerShell script changes the current working directory to the folder for Git repositories.
.EXAMPLE
PS> ./cd-repos.ps1
📂C:\Repos with 33 folders entered.
@ -32,6 +32,6 @@ try {
"📂$path with $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux -or $IsMacOS) { $path = "/" } else { $path = "C:\" }
Set-Location "$path"
@ -20,6 +22,6 @@ try {
"📂$path with $($folders.Count) folders and $($files.Count) files entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
function GetScreenshotsFolder {
if ($IsLinux) {
if (-not(Test-Path "~/Pictures" -pathType container)) { throw "No 'Pictures' folder in your home directory yet" }
@ -33,6 +35,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Sets the working directory to the PowerShell scripts folder
.DESCRIPTION
This PowerShell script changes the working directory to the PowerShell scripts folder.
This PowerShell script changes the currrent working directory to the PowerShell scripts folder.
.EXAMPLE
PS> ./cd-scripts.ps1
📂C:\Repos\PowerShell\scripts with 655 scripts entered.
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$path" -pathType container)) { throw "No scripts folder at: $path" }
@ -20,6 +22,6 @@ try {
"📂$path with $($files.Count) scripts entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,10 +12,12 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = "~/.ssh"
if (-not(Test-Path "$path" -pathType container)) {
throw "Your home directory has no '.ssh' folder yet - Please install SSH."
throw "No '.ssh' folder in your home directory yet - Please install SSH."
}
$path = Resolve-Path "$path"
Set-Location "$path"

View File

@ -12,9 +12,11 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (-not(Test-Path "~/Sync" -pathType container)) {
throw "Your home directory has no 'Sync' folder yet - Please install Syncthing."
throw "No 'Sync' folder in your home directory yet - Please install Syncthing."
}
$path = Resolve-Path "~/Sync"
Set-Location "$path"

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
function GetTempDir {
if ("$env:TEMP" -ne "") { return "$env:TEMP" }
if ("$env:TMP" -ne "") { return "$env:TMP" }
@ -21,9 +23,7 @@ function GetTempDir {
try {
$path = GetTempDir
if (-not(Test-Path "$path" -pathType container)) { throw
"No temporary folder at: $path"
}
if (-not(Test-Path "$path" -pathType container)) { throw "No temporary folder at: $path" }
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory

View File

@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) {
if (-not(Test-Path "~/Templates" -pathType container)) {
@ -30,6 +32,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,9 +2,9 @@
.SYNOPSIS
Sets the working dir to the trash folder
.DESCRIPTION
This PowerShell script changes the working directory to the user's trash folder.
This PowerShell script changes the current working directory to the user's trash folder.
.EXAMPLE
PS> ./cd-trash
PS> ./cd-trash.ps1
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 with 4 files and 0 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
@ -35,6 +35,6 @@ try {
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -2,9 +2,9 @@
.SYNOPSIS
Sets the working directory to one level up
.DESCRIPTION
This PowerShell script changes the working directory to one directory level up.
This PowerShell script changes the current working directory to one directory level up.
.EXAMPLE
PS> .\cd-up
PS> .\cd-up.ps1
📂C:\Users
.LINK
https://github.com/fleschutz/PowerShell
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path ".."
if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" }
@ -19,6 +21,6 @@ try {
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -1,10 +1,10 @@
<#
.SYNOPSIS
Sets the working directory to two directory levels up
Sets the working directory 2 directory levels up
.DESCRIPTION
This PowerShell script changes the working directory to two directory level up.
This PowerShell script changes the current working directory to two directory level up.
.EXAMPLE
PS> ./cd-up2
PS> ./cd-up2.ps1
📂C:\
.LINK
https://github.com/fleschutz/PowerShell
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "../.."
if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" }
@ -19,6 +21,6 @@ try {
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -1,10 +1,10 @@
<#
.SYNOPSIS
Sets the working directory to three directory levels up
Sets the working directory 3 directory levels up
.DESCRIPTION
This PowerShell script changes the working directory to three directory levels up.
This PowerShell script changes the current working directory to three directory levels up.
.EXAMPLE
PS> ./cd-up3
PS> ./cd-up3.ps1
📂C:\
.LINK
https://github.com/fleschutz/PowerShell
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "../../.."
if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" }
@ -19,6 +21,6 @@ try {
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -1,10 +1,10 @@
<#
.SYNOPSIS
Sets the working directory to four directory levels up
Sets the working directory 4 directory levels up
.DESCRIPTION
This PowerShell script changes the working directory to four directory levels up.
This PowerShell script changes the current working directory to four directory levels up.
.EXAMPLE
PS> ./cd-up4
PS> ./cd-up4.ps1
📂C:\
.LINK
https://github.com/fleschutz/PowerShell
@ -12,6 +12,8 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "../../../.."
if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" }
@ -19,6 +21,6 @@ try {
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -12,16 +12,17 @@
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$path = Resolve-Path "~/.."
if (-not(Test-Path "$path" -pathType container)) {
throw "No users directory at: $path"
}
if (-not(Test-Path "$path" -pathType container)) { throw "No users directory at: $path" }
Set-Location "$path"
$folders = Get-ChildItem $path -attributes Directory
"📂$path with $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}

View File

@ -4,14 +4,16 @@
.DESCRIPTION
This PowerShell script changes the working directory to the user's videos folder.
.EXAMPLE
PS> ./cd-videos
📂C:\Users\Markus\Videos entered (has 3 files and 0 subfolders)
PS> ./cd-videos.ps1
📂C:\Users\Markus\Videos with 3 files and 0 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if ($IsLinux) {
$path = Resolve-Path "~/Videos"
@ -24,9 +26,9 @@ try {
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
"⚠️ ERROR: $($Error[0])"
exit 1
}