mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-28 08:38:38 +01:00
Update cd-repos.ps1
This commit is contained in:
parent
d5e5f5cecf
commit
6531d14f66
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user