-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartSemester.ps1
More file actions
62 lines (54 loc) · 1.72 KB
/
Copy pathstartSemester.ps1
File metadata and controls
62 lines (54 loc) · 1.72 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Usage example:
# startSemester.ps1 -Classes co-op,MATH-342
param (
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
[string[]]$Classes
)
if ($Classes.Count -eq 0) {
Write-Host "Usage example: .\startSemester.ps1 -Classes co-op,MATH-342"
exit
}
foreach ($class in $Classes) {
if (Test-Path $class -PathType Container) {
Write-Host "Directory $class already exists"
Set-Location $class
}
else {
New-Item -ItemType Directory -Name $class | Out-Null
Write-Host "Created directory $class"
Set-Location $class
}
$exists = $false
& git rev-parse --is-inside-work-tree *>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Local git repo for $class already exists"
$exists = $true
}
else {
& git init
}
foreach ($subdir in "Assignments","Labs","Notes") {
if (!(Test-Path $subdir -PathType Container)) {
New-Item -ItemType Directory -Name $subdir | Out-Null
New-Item -Path "$subdir\.gitkeep" -ItemType File | Out-Null
}
}
if (!(Test-Path ".gitignore")) { New-Item -ItemType File -Name ".gitignore" | Out-Null }
if (!(Test-Path "README.md")) { New-Item -ItemType File -Name "README.md" | Out-Null }
Write-Host "Created subfolders in $class"
& git add .
if ($exists) {
& git commit -m "Updating commit after init.ps1 in $class"
}
else {
& git commit -m "Initial commit for $class"
}
& gh repo view $class *>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "GitHub repository $class already exists"
Set-Location ..
continue
}
& gh repo create $class --private --push --source .
Set-Location ..
}