-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-get-gitaddcommand.ps1
More file actions
145 lines (109 loc) · 3.23 KB
/
Copy pathfunction-get-gitaddcommand.ps1
File metadata and controls
145 lines (109 loc) · 3.23 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<#
.Synopsis
Generates a 'git add' command for everything that has been changed but not added
.DESCRIPTION
Generates a 'git add' command for everything that has been changed but not added.
There's probably a better way to do this within git itself, but I couldn't find it!
Todo: implement swapping to a folder or folders and generating cd commands and got add commands
.EXAMPLE
get-gitaddcommand
git add .gitignore function-convertto-twiki.ps1 function-edit-powershellref.ps1 function-get-gitaddcommand.ps1
.EXAMPLE
Another example of how to use this cmdlet
#>
function Get-MTPGitAddCommand
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
[Parameter(Position=0)]
$FolderName = ".",
[string]$Option = "All"
)
$GitStatusOutput = get-MTPGetGitStatus
get-MTPGitUntrackedFilesCommands -GitStatusOutput $GitStatusOutput
get-MTPGitModifiedFilesCommands -GitStatusOutput $GitStatusOutput
}
function get-MTPGitModifiedFilesCommands
{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
$GitStatusOutput
)
$ModifiedFiles = get-MTPGitModifiedFiles -GitStatusOutput $GitStatusOutput
foreach ($F in $ModifiedFiles)
{
[string]$File = $F.Line
$File = $File.trim()
write-output "git add `"$File`""
}
}
function get-MTPGitUntrackedFilesCommands
{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
$GitStatusOutput
)
$UntrackedFiles = get-MTPGitUntrackedFiles -GitStatusOutput $GitStatusOutput
foreach ($F in $UntrackedFiles)
{
[string]$File = $F.Line
$File = $File.trim()
write-output "git add `"$File`""
}
}
function get-MTPGitStatus
{
[CmdletBinding()]
$GitStatusOutput = git status | select-string '^'
$GitStatusOutput = $GitStatusOutput |
where-object Line -notlike "*~" |
where-object Line -notlike "*swp*" |
where-object Line -notlike "*swo" |
where-object Line -notlike '(use "git add <file>..." to include in what will be committed)*'
$GitStatusOutput
}
function get-MTPGitUntrackedFiles
{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
$GitStatusOutput,
[string]$UntrackedFilesString = "Untracked files:"
)
$UntrackedFilesLine = $GitStatusOutput | ? line -Like "$UntrackedFilesString*"
[int]$UntrackedFilesLineNumber = $UntrackedFilesLine.LineNumber
$Untracked = $GitStatusOutput | ? linenumber -gt $UntrackedFilesLineNumber
$Untracked
}
function get-MTPGitModifiedFiles
{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
$GitStatusOutput,
[string]$UntrackedFilesString = "Untracked files:"
)
$UntrackedFilesLine = $GitStatusOutput | ? line -Like "$UntrackedFilesString*"
[int]$UntrackedFilesLineNumber = $UntrackedFilesLine.LineNumber
$Modified = $GitStatusOutput |
? linenumber -lt $UntrackedFilesLineNumber |
? line -like "*modified:*"
$ModifiedFiles = @()
foreach ($F in $Modified)
{
[string]$Line = $F.Line
write-host "$Line"
$ModifiedFiles += [PSCustomObject]@{Line = $Line.split(':')[1] }
}
$ModifiedFiles
}
set-alias ggac get-gitaddcommand