mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-26 01:43:37 +01:00
84 lines
2.1 KiB
Markdown
84 lines
2.1 KiB
Markdown
*cd-repos.ps1*
|
|
================
|
|
|
|
This PowerShell script changes the working directory to the user's Git repositories folder.
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
PS> ./cd-repos.ps1 [[-Subpath] <String>] [<CommonParameters>]
|
|
|
|
-Subpath <String>
|
|
Specifies an additional relative subpath (optional)
|
|
|
|
Required? false
|
|
Position? 1
|
|
Default value
|
|
Accept pipeline input? false
|
|
Accept wildcard characters? false
|
|
|
|
[<CommonParameters>]
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
```
|
|
|
|
Example
|
|
-------
|
|
```powershell
|
|
PS> ./cd-repos
|
|
📂C:\Users\Markus\source\Repos
|
|
|
|
```
|
|
|
|
Notes
|
|
-----
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
Related Links
|
|
-------------
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
Script Content
|
|
--------------
|
|
```powershell
|
|
<#
|
|
.SYNOPSIS
|
|
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\source\Repos
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz | License: CC0
|
|
#>
|
|
|
|
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"
|
|
} else {
|
|
throw "The folder for Git repositories in your home directory 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: $($Error[0])"
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of cd-repos.ps1 as of 09/20/2023 17:04:37)*
|