mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-16 10:58:55 +01:00
Updated cd-repos.ps1 and cd-scripts.ps1
This commit is contained in:
parent
6625d4a909
commit
95e3305c9d
@ -3,7 +3,7 @@
|
|||||||
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
|
.PARAMETER subpath
|
||||||
Specifies an additional relative subpath (optional)
|
Specifies an additional relative subpath (optional)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-repos
|
PS> ./cd-repos
|
||||||
@ -14,22 +14,28 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$Subpath = "")
|
param([string]$subpath = "")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Test-Path "$HOME/Repos" -pathType Container) { # try short name
|
if (Test-Path "$HOME/Repos/" -pathType Container) { # try short name
|
||||||
$Path = "$HOME/Repos/$Subpath"
|
$path = "$HOME/Repos/"
|
||||||
} elseif (Test-Path "$HOME/Repositories" -pathType Container) { # try long name
|
} elseif (Test-Path "$HOME/repos/" -pathType Container) {
|
||||||
$Path = "$HOME/Repositories/$Subpath"
|
$path = "$HOME/repos/"
|
||||||
} elseif (Test-Path "$HOME/source/repos" -pathType Container) { # try Visual Studio default
|
} elseif (Test-Path "$HOME/Repositories/" -pathType Container) { # try long name
|
||||||
$Path = "$HOME/source/repos/$Subpath"
|
$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 {
|
} 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)." }
|
if ("$subpath" -ne "") { $path += $subpath }
|
||||||
$Path = Resolve-Path "$Path"
|
if (-not(Test-Path "$path" -pathType Container)) { throw "The path to 📂$path doesn't exist (yet)" }
|
||||||
Set-Location "$Path"
|
$path = Resolve-Path "$path"
|
||||||
"📂$Path"
|
Set-Location "$path"
|
||||||
|
"📂$path"
|
||||||
|
if ("$subpath" -ne "") { & git status --short --branch --show-stash }
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the working directory to the PowerShell scripts folder.
|
This PowerShell script changes the working directory to the PowerShell scripts folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-scripts
|
PS> ./cd-scripts
|
||||||
📂C:\Users\Markus\source\repos\PowerShell\scripts
|
📂C:\Users\Markus\Repos\PowerShell\scripts
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,10 +13,10 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Path = Resolve-Path "$PSScriptRoot"
|
$path = Resolve-Path "$PSScriptRoot"
|
||||||
if (-not(Test-Path "$Path" -pathType container)) { throw "PowerShell scripts folder at 📂$Path doesn't exist (yet)" }
|
if (-not(Test-Path "$path" -pathType container)) { throw "PowerShell scripts folder at 📂$path doesn't exist (yet)" }
|
||||||
Set-Location "$Path"
|
Set-Location "$path"
|
||||||
"📂$Path"
|
"📂$path"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user