Skip to content

Commit 82156d8

Browse files
author
Markus Fleschutz
committed
Updated cd-repo.ps1 and cd-repos.ps1
1 parent cb845c5 commit 82156d8

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

scripts/cd-repo.ps1

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
Specifies the folder name of the Git repository
88
.EXAMPLE
99
PS> ./cd-repo.ps1 rust
10-
📂C:\Repos\rust
11-
🌿on branch: ## main ... origin/main
10+
📂C:\Repos\rust · on branch: ## main ... origin/main
1211
.LINK
1312
https://github.com/fleschutz/PowerShell
1413
.NOTES
@@ -20,26 +19,33 @@ param([string]$folderName = "")
2019
try {
2120
if ("$folderName" -eq "") { $folderName = Read-Host "Enter the Git repository's folder name" }
2221

23-
if (Test-Path "~/Repos/" -pathType container) { # try short name
24-
$path = "~/Repos/"
25-
} elseif (Test-Path "~/repos/" -pathType container) {
26-
$path = "~/repos/"
27-
} elseif (Test-Path "~/Repositories/" -pathType container) { # try long name
28-
$path = "~/Repositories/"
29-
} elseif (Test-Path "~/source/repos/" -pathType container) { # try Visual Studio default
30-
$path = "~/source/repos/"
31-
} elseif (Test-Path "/Repos/" -pathType container) {
32-
$path = "/Repos/"
22+
if (Test-Path "~/Repos" -pathType Container) { # try short name in home dir
23+
$path = "~/Repos"
24+
} elseif (Test-Path "~/repos" -pathType Container) {
25+
$path = "~/repos"
26+
} elseif (Test-Path "~/Repositories" -pathType Container) { # try long name
27+
$path = "~/Repositories"
28+
} elseif (Test-Path "~/repositories" -pathType Container) {
29+
$path = "~/repositories"
30+
} elseif (Test-Path "/Repos" -pathType Container) { # try short name in root dir
31+
$path = "/Repos"
32+
} elseif (Test-Path "/repos" -pathType Container) {
33+
$path = "/repos"
34+
} elseif (Test-Path "/Repositories" -pathType Container) { # try long name
35+
$path = "/Repositories"
36+
} elseif (Test-Path "/repositories" -pathType Container) {
37+
$path = "/repositories"
38+
} elseif (Test-Path "~/source/repos" -pathType Container) { # try Visual Studio default
39+
$path = "~/source/repos"
3340
} else {
34-
throw "The folder for Git repositories doesn't exist (yet)"
41+
throw "No Git repositories folder in your home directory or in the root folder yet"
3542
}
36-
37-
$path += $folderName
43+
$path += "/" + $folderName
3844
if (-not(Test-Path "$path" -pathType container)) { throw "The path to 📂$path doesn't exist (yet)" }
3945

4046
$path = Resolve-Path "$path"
4147
Set-Location "$path"
42-
Write-Host "📂$path`n🌿on branch: " -noNewline
48+
Write-Host "📂$path · on branch: " -noNewline
4349
& git status --short --branch --show-stash
4450
exit 0 # success
4551
} catch {

scripts/cd-repos.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ try {
3131
$path = "/Repositories"
3232
} elseif (Test-Path "/repositories" -pathType Container) {
3333
$path = "/repositories"
34-
} elseif (Test-Path "~/source/repos/" -pathType Container) { # try Visual Studio default
35-
$path = "~/source/repos/"
34+
} elseif (Test-Path "~/source/repos" -pathType Container) { # try Visual Studio default
35+
$path = "~/source/repos"
3636
} else {
3737
throw "No Git repositories folder in your home directory or in the root folder yet"
3838
}

0 commit comments

Comments
 (0)