diff --git a/Scripts/cd-repos.ps1 b/Scripts/cd-repos.ps1 index 2d11cbfb..62aa71b6 100755 --- a/Scripts/cd-repos.ps1 +++ b/Scripts/cd-repos.ps1 @@ -3,6 +3,8 @@ 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 + Specifies an additional relative subpath (optional) .EXAMPLE PS> ./cd-repos 📂C:\Users\Markus\Repos @@ -12,21 +14,26 @@ Author: Markus Fleschutz | License: CC0 #> +param([string]$Subpath = "") + try { - if (Test-Path "$HOME/Repos" -pathType Container) { - $Path = Resolve-Path "$HOME/Repos" # short form - } elseif (Test-Path "$HOME/Repositories" -pathType Container) { - $Path = Resolve-Path "$HOME/Repositories" # long form - } elseif (Test-Path "$HOME/source/repos" -pathType Container) { - $Path = Resolve-Path "$HOME/source/repos" # default by Visual Studio + 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" } else { - $Path = "$HOME/Repos" - throw "Folder for Git repositories at 📂$Path doesn't exist (yet)" + throw "The folder for Git repositories at 📂$HOME/Reposh 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" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } \ No newline at end of file