-
Notifications
You must be signed in to change notification settings - Fork 1
/
GitPullNormalized.ps1
109 lines (96 loc) · 3.71 KB
/
GitPullNormalized.ps1
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Function to run git pull in a selected directory
function RunGitPull {
param (
[string]$directory
)
Set-Location -Path $directory
Write-Host "`nUpdating $directory..."
Invoke-Expression "git pull"
Set-Location -Path $rootDirectory
Write-Host "Completed pulling repository in $directory.`n"
}
# Function to normalize directory names
function NormalizeDirectoryName {
param (
[string]$name
)
$name = $name -replace "_", ""
$name = $name -replace "-", ""
$name = $name -replace "comfyui", ""
return $name
}
# Function to display directories and handle user selection
function DisplayDirectoriesAndHandleSelection {
param (
[array]$directories,
[bool]$normalize
)
for ($i = 0; $i -lt $directories.Count; $i++) {
$displayName = $directories[$i].Name
if ($normalize) {
$displayName = NormalizeDirectoryName $displayName
}
Write-Host "$($i+1): $displayName"
}
Write-Host "" # Line break for better readability
$selection = Read-Host "Enter the number of the directory to update, a search term, or 'exit' to quit"
if ($selection -eq 'exit') {
return "exit"
}
if ($selection -match "^\d+$") {
$selectedIndex = $selection - 1
if ($selectedIndex -ge 0 -and $selectedIndex -lt $directories.Count) {
return $directories[$selectedIndex].FullName
} else {
Write-Host "`nInvalid selection. Please try again.`n"
return $null
}
} else {
# Handle as search term
return "search:$selection"
}
}
# Get the current directory
$rootDirectory = Get-Location
# Prompt user to choose normalization
$normalize = Read-Host "`nDo you want to normalize directory names by removing '_', '-', and 'comfyui'? (Y/N) [Default: Y]"
if ($normalize -eq '' -or $normalize.ToLower() -eq 'y') {
$normalize = $true
} else {
$normalize = $false
}
# Infinite loop to keep the script running
while ($true) {
# Get all root directories and sort them alphabetically
$subDirectories = Get-ChildItem -Directory | Sort-Object Name
$result = DisplayDirectoriesAndHandleSelection -directories $subDirectories -normalize $normalize
if ($result -eq "exit") {
break
} elseif ($result -eq $null) {
continue
} elseif ($result.StartsWith("search:")) {
$searchTerm = $result.Substring(7)
$filteredDirectories = $subDirectories | Where-Object { $_.Name -like "*$searchTerm*" }
if ($filteredDirectories.Count -eq 0) {
Write-Host "`nNo directories found with the term '$searchTerm'.`n"
} else {
Write-Host "`nDirectories matching '$searchTerm':`n"
$selectedDirectory = DisplayDirectoriesAndHandleSelection -directories $filteredDirectories -normalize $normalize
if ($selectedDirectory -eq "exit") {
break
} elseif ($selectedDirectory -ne $null) {
# Confirm with user
$confirmation = Read-Host "`nAre you sure you want to run git pull in '$(Split-Path -Leaf $selectedDirectory)'? (Y/N) [Default: Y]`n"
if ($confirmation -eq '' -or $confirmation.ToLower() -eq 'y') {
RunGitPull -directory $selectedDirectory
}
}
}
} else {
# Confirm with user
$confirmation = Read-Host "`nAre you sure you want to run git pull in '$(Split-Path -Leaf $result)'? (Y/N) [Default: Y]`n"
if ($confirmation -eq '' -or $confirmation.ToLower() -eq 'y') {
RunGitPull -directory $result
}
}
}