Update cd-repos.ps1

This commit is contained in:
Markus Fleschutz 2022-11-25 14:27:24 +01:00
parent d5e5f5cecf
commit 6531d14f66

View File

@ -3,6 +3,8 @@
Sets the working directory to the user's repos folder Sets the working directory to the user's repos folder
.DESCRIPTION .DESCRIPTION
This PowerShell script changes the working directory to the user's Git repositories folder. This PowerShell script changes the working directory to the user's Git repositories folder.
.PARAMETER Subpath
Specifies an additional relative subpath (optional)
.EXAMPLE .EXAMPLE
PS> ./cd-repos PS> ./cd-repos
📂C:\Users\Markus\Repos 📂C:\Users\Markus\Repos
@ -12,21 +14,26 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$Subpath = "")
try { try {
if (Test-Path "$HOME/Repos" -pathType Container) { if (Test-Path "$HOME/Repos" -pathType Container) { # try short name
$Path = Resolve-Path "$HOME/Repos" # short form $Path = "$HOME/Repos/$Subpath"
} elseif (Test-Path "$HOME/Repositories" -pathType Container) { } elseif (Test-Path "$HOME/Repositories" -pathType Container) { # try long name
$Path = Resolve-Path "$HOME/Repositories" # long form $Path = "$HOME/Repositories/$Subpath"
} elseif (Test-Path "$HOME/source/repos" -pathType Container) { } elseif (Test-Path "$HOME/source/repos" -pathType Container) { # try Visual Studio default
$Path = Resolve-Path "$HOME/source/repos" # default by Visual Studio $Path = "$HOME/source/repos/$Subpath"
} else { } else {
$Path = "$HOME/Repos" throw "The folder for Git repositories at 📂$HOME/Reposh doesn't exist (yet)."
throw "Folder for Git repositories at 📂$Path 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" Set-Location "$Path"
"📂$Path" "📂$Path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }