-
-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathcd-repos.ps1
More file actions
executable file
·44 lines (42 loc) · 2.1 KB
/
cd-repos.ps1
File metadata and controls
executable file
·44 lines (42 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<#
.SYNOPSIS
Sets the working dir to the repos folder
.DESCRIPTION
This PowerShell script changes the current working directory to the Git repositories folder.
.EXAMPLE
PS> ./cd-repos.ps1
📂C:\Repos entered, has 33 subfolders.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
if (Test-Path "~/Repos" -pathType container) { $path = "~/Repos"
} elseif (Test-Path "~/repos" -pathType container) { $path = "~/repos"
} elseif (Test-Path "~/Repositories" -pathType container) { $path = "~/Repositories"
} elseif (Test-Path "~/repositories" -pathType container) { $path = "~/repositories"
} elseif (Test-Path "~/Git" -pathType container) { $path = "~/Git"
} elseif (Test-Path "~/git" -pathType container) { $path = "~/git"
} elseif (Test-Path "/Repos" -pathType container) { $path = "/Repos"
} elseif (Test-Path "/repos" -pathType container) { $path = "/repos"
} elseif (Test-Path "/Repositories" -pathType container) { $path = "/Repositories"
} elseif (Test-Path "/repositories" -pathType container) { $path = "/repositories"
} elseif (Test-Path "/Git" -pathType container) { $path = "/Git"
} elseif (Test-Path "/git" -pathType container) { $path = "/git"
} elseif (Test-Path "~/source/repos" -pathType container) { $path = "~/source/repos" # Visual Studio default
} elseif (Test-Path "D:/Repos" -pathType container) { $path = "D:/Repos" # on HDD
} elseif (Test-Path "D:/Repositories" -pathType container) { $path = "D:/Repositories" # on HDD
} elseif (Test-Path "D:/Git" -pathType container) { $path = "D:/Git" # on HDD
} elseif (Test-Path "D:/git" -pathType container) { $path = "D:/git" # on HDD
} else { throw "Found no folder for Git repositories (in home or root directory) - Please create one." }
$path = Resolve-Path $path
Set-Location "$path"
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered, has $($folders.Count) subfolders."
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0])"
exit 1
}