Updated cd-repos.ps1 and cd-scripts.ps1

This commit is contained in:
Markus Fleschutz 2024-03-06 08:25:34 +01:00
parent 6625d4a909
commit 95e3305c9d
2 changed files with 24 additions and 18 deletions

View File

@ -3,7 +3,7 @@
Sets the working directory to the user's repos folder
.DESCRIPTION
This PowerShell script changes the working directory to the user's Git repositories folder.
.PARAMETER Subpath
.PARAMETER subpath
Specifies an additional relative subpath (optional)
.EXAMPLE
PS> ./cd-repos
@ -14,22 +14,28 @@
Author: Markus Fleschutz | License: CC0
#>
param([string]$Subpath = "")
param([string]$subpath = "")
try {
if (Test-Path "$HOME/Repos" -pathType Container) { # try short name
$Path = "$HOME/Repos/$Subpath"
} elseif (Test-Path "$HOME/Repositories" -pathType Container) { # try long name
$Path = "$HOME/Repositories/$Subpath"
} elseif (Test-Path "$HOME/source/repos" -pathType Container) { # try Visual Studio default
$Path = "$HOME/source/repos/$Subpath"
if (Test-Path "$HOME/Repos/" -pathType Container) { # try short name
$path = "$HOME/Repos/"
} elseif (Test-Path "$HOME/repos/" -pathType Container) {
$path = "$HOME/repos/"
} elseif (Test-Path "$HOME/Repositories/" -pathType Container) { # try long name
$path = "$HOME/Repositories/"
} elseif (Test-Path "$HOME/source/repos/" -pathType Container) { # try Visual Studio default
$path = "$HOME/source/repos/"
} elseif (Test-Path "/Repos/" -pathType Container) {
$path = "/Repos/"
} else {
throw "The folder for Git repositories in your home directory doesn't exist (yet)."
throw "The folder for Git repositories doesn't exist (yet)"
}
if (-not(Test-Path "$Path" -pathType Container)) { throw "The path to 📂$Path doesn't exist (yet)." }
$Path = Resolve-Path "$Path"
Set-Location "$Path"
"📂$Path"
if ("$subpath" -ne "") { $path += $subpath }
if (-not(Test-Path "$path" -pathType Container)) { throw "The path to 📂$path doesn't exist (yet)" }
$path = Resolve-Path "$path"
Set-Location "$path"
"📂$path"
if ("$subpath" -ne "") { & git status --short --branch --show-stash }
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the PowerShell scripts folder.
.EXAMPLE
PS> ./cd-scripts
📂C:\Users\Markus\source\repos\PowerShell\scripts
📂C:\Users\Markus\Repos\PowerShell\scripts
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -13,10 +13,10 @@
#>
try {
$Path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$Path" -pathType container)) { throw "PowerShell scripts folder at 📂$Path doesn't exist (yet)" }
Set-Location "$Path"
"📂$Path"
$path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$path" -pathType container)) { throw "PowerShell scripts folder at 📂$path doesn't exist (yet)" }
Set-Location "$path"
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"