This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
forked from simonwhitaker/gibo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgabo.bat
191 lines (143 loc) · 5.33 KB
/
gabo.bat
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
@rem #!/dos/rocks!
@setlocal EnableDelayedExpansion
@echo off
rem Script for easily accessing gitattributes boilerplates from
rem https://github.com/alexkaratarakis/gitattributes
rem
rem Change log
rem v1.0 1-May-2012 First public release
rem v1.0.01 16-Aug-2014 Added batch file for DOS by Kody Brown ^<thewizard@wasatchwizard.com^>
rem v2.0.00 11-Jun-2018 Updated to v2; subcommand model by Simon Whitaker ^<sw@netcetera.org^>
rem v2.0.01 13-Jun-2018 Added optional parameter for list subcommand, added search subcommand, added support for GIBO_BOILERPLATES by Kody Brown ^<thewizard@wasatchwizard.com^>
goto :setup
:version
echo %basename% 2.3.1 by Jarrod Davis ^<developer@jarrodldavis.com^>
echo https://github.com/jarrodldavis/gabo
goto :eof
:usage
call :version
echo.
echo Fetches gitattributes boilerplates from github.com/alexkaratarakis/gitattributes
echo.
echo Usage:
echo %basename% [command]
echo.
echo Example:
echo %basename% dump Common CSharp VisualStudio ^>^> .gitattributes
echo.
echo Options:
echo dump expr... Dump boilerplate(s) to stdout
echo help Display this help text
echo list List available boilerplates
echo root Show the directory where gabo stores its boilerplates
echo search expr Search inside boilerplates for expr
echo update Update list of available boilerplates
echo version Display current script version
goto :eof
:setup
set "basename=%~n0"
set "baseext=%~x0"
set "basepath=%~dp0"
set "__cloned="
set "dumping="
set "remote_repo=https://github.com/alexkaratarakis/gitattributes.git"
rem Allow using the `GABO_BOILERPLATES` system envar
rem for specifying the boilerplates directory.
if defined GABO_BOILERPLATES set "local_repo=%GABO_BOILERPLATES%"
if not defined GABO_BOILERPLATES set "local_repo=%AppData%\.gitattributes-boilerplates"
rem No args passed in, so show usage.
if "%~1"=="" call :usage && goto :end
:parse
rem Parse comand-line options.
if "%~1"=="" goto :end
set a=%~1
rem The batch file's equivalent 'Sanity check' is that any
rem options (-, --, and / for Windows) are executed then
rem the batch file exits, ignoring any other commands, such
rem as Python, etc.
if /i "%a%"=="help" call :usage & goto :end
if /i "%a%"=="/?" call :usage & goto :end
if /i "%a%"=="version" call :version & goto :end
if /i "%a%"=="/v" call :version & goto :end
if /i "%a%"=="list" call :list "%~2" & goto :end
if /i "%a%"=="root" call :root & goto :end
if /i "%a%"=="search" call :search "%~2" & goto :end
if /i "%a%"=="update" call :update & goto :end
if /i "%a%"=="dump" set "dumping=1" & shift & goto :parse
if defined dumping call :dump "%a%" & shift & goto :parse
goto :invalid_argument "%a%"
:end
@endlocal && exit /B 0
:invalid_argument "arg"
echo Invalid argument: %~1
echo Did you mean:
rem Is there a .gitattributes file?
set "_foundfile="
if exist "%local_repo%\%~1.gitattributes" set "_foundfile=yes"
if exist "%local_repo%\Global\%~1.gitattributes" set "_foundfile=yes"
if defined _foundfile (
echo `%basename% dump %*`
echo `%basename% list %*`
)
rem Did the user mean to search within .gitattributes files?
echo `%basename% search %*`
endlocal && exit /B 1
:clone [--silently]
if "%~1"=="--silently" ( set "opt=-q" ) else ( set "opt=" )
git clone %opt% "%remote_repo%" "%local_repo%"
goto :eof
:init [--silently]
if not exist "%local_repo%\.git" set "__cloned=yes" && call :clone "%~1"
goto :eof
:list
call :init
echo === Boilerplates ===
echo.
for /f %%G in ('dir /b /on "%local_repo%\*%~1*.gitattributes"') do (
echo %%~nG
)
goto :eof
:root
echo %local_repo%
goto :eof
:search
if "%~1"=="" echo %basename%: missing search expr.. && goto :eof
call :init
rem `findstr` options:
rem /R Uses search strings as regular expressions.
rem /S Searches for matching files in the current directory and all
rem subdirectories.
rem /I Specifies that the search is not to be case-sensitive.
rem /N Prints the line number before each line that matches.
rem /P Skip files with non-printable characters.
rem /A:attr Specifies color attribute with two hex digits. See "color /?"
rem strings Text to be searched for.
rem [drive:][path]filename
rem Specifies a file or files to search.
pushd "%local_repo%"
findstr /S /R /I /N /P /A:03 "%~1" *.gitattributes
popd
goto :eof
:update
call :init
rem If the repo was just cloned, don't perform a `pull`
if not defined __cloned (
echo updating..
pushd "%local_repo%"
git pull -q --ff origin master
popd
)
goto :eof
:dump
call :init --silently
set "boilerplate_file=%local_repo%\%~1.gitattributes"
if exist "%boilerplate_file%" (
echo ### %~1
echo.
type "%boilerplate_file%"
echo.
echo.
) else (
echo Unknown argument: %~1
)
goto :eof