mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-24 17:03:45 +01:00
Updated cd-repo.ps1 and cd-ssh.ps1
This commit is contained in:
parent
bd3b301072
commit
2a009f311f
@ -1,13 +1,13 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Sets the working directory to a repository
|
Sets the working directory to a repo
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script changes the working directory to a local Git repository.
|
This PowerShell script changes the working directory to the given local Git repository.
|
||||||
.PARAMETER folderName
|
.PARAMETER folderName
|
||||||
Specifies the Git repository's folder name
|
Specifies the folder name of the Git repository
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-repo.ps1 rust
|
PS> ./cd-repo.ps1 rust
|
||||||
📂C:\Repos\rust - current branch is: ## main ... origin/main
|
📂C:\Repos\rust · on branch: ## main ... origin/main
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -19,25 +19,26 @@ param([string]$folderName = "")
|
|||||||
try {
|
try {
|
||||||
if ("$folderName" -eq "") { $folderName = Read-Host "Enter the Git repository's folder name" }
|
if ("$folderName" -eq "") { $folderName = Read-Host "Enter the Git repository's folder name" }
|
||||||
|
|
||||||
if (Test-Path "$HOME/Repos/" -pathType Container) { # try short name
|
if (Test-Path "~/Repos/" -pathType container) { # try short name
|
||||||
$path = "$HOME/Repos/"
|
$path = "~/Repos/"
|
||||||
} elseif (Test-Path "$HOME/repos/" -pathType Container) {
|
} elseif (Test-Path "~/repos/" -pathType container) {
|
||||||
$path = "$HOME/repos/"
|
$path = "~/repos/"
|
||||||
} elseif (Test-Path "$HOME/Repositories/" -pathType Container) { # try long name
|
} elseif (Test-Path "~/Repositories/" -pathType container) { # try long name
|
||||||
$path = "$HOME/Repositories/"
|
$path = "~/Repositories/"
|
||||||
} elseif (Test-Path "$HOME/source/repos/" -pathType Container) { # try Visual Studio default
|
} elseif (Test-Path "~/source/repos/" -pathType container) { # try Visual Studio default
|
||||||
$path = "$HOME/source/repos/"
|
$path = "~/source/repos/"
|
||||||
} elseif (Test-Path "/Repos/" -pathType Container) {
|
} elseif (Test-Path "/Repos/" -pathType container) {
|
||||||
$path = "/Repos/"
|
$path = "/Repos/"
|
||||||
} else {
|
} else {
|
||||||
throw "The folder for Git repositories doesn't exist (yet)"
|
throw "The folder for Git repositories doesn't exist (yet)"
|
||||||
}
|
}
|
||||||
$path += $folderName
|
|
||||||
|
|
||||||
if (-not(Test-Path "$path" -pathType Container)) { throw "The path to 📂$path doesn't exist (yet)" }
|
$path += $folderName
|
||||||
|
if (-not(Test-Path "$path" -pathType container)) { throw "The path to 📂$path doesn't exist (yet)" }
|
||||||
|
|
||||||
$path = Resolve-Path "$path"
|
$path = Resolve-Path "$path"
|
||||||
Set-Location "$path"
|
Set-Location "$path"
|
||||||
Write-Host "📂$path - current branch is: " -noNewline
|
Write-Host "📂$path · on branch: " -noNewline
|
||||||
& git status --short --branch --show-stash
|
& git status --short --branch --show-stash
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Sets the working directory to the user's SSH folder
|
Sets the working directory to the SSH folder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script changes the working directory to the user's SSH folder.
|
This PowerShell script changes the working directory to the user's secure shell (SSH) folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-ssh
|
PS> ./cd-ssh.ps1
|
||||||
📂C:\Users\Markus\.ssh
|
📂C:\Users\Markus\.ssh
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
@ -13,12 +13,13 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Path = Resolve-Path "~/.ssh"
|
$path = "~/.ssh"
|
||||||
if (-not(Test-Path "$Path" -pathType container)) { throw "User's SSH folder at 📂$Path doesn't exist (yet)" }
|
if (-not(Test-Path "$path" -pathType container)) { throw "Your secure shell (SSH) folder at 📂$path doesn't exist (yet)" }
|
||||||
Set-Location "$Path"
|
$path = Resolve-Path "$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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user