remote: handle negative refspecs in git remote show
[alt-git.git] / contrib / vscode / init.sh
blobf139fd864446262da45cc5ed9bb4180beae2b5a0
1 #!/bin/sh
3 die () {
4 echo "$*" >&2
5 exit 1
8 cd "$(dirname "$0")"/../.. ||
9 die "Could not cd to top-level directory"
11 mkdir -p .vscode ||
12 die "Could not create .vscode/"
14 # General settings
16 cat >.vscode/settings.json.new <<\EOF ||
18 "C_Cpp.intelliSenseEngine": "Default",
19 "C_Cpp.intelliSenseEngineFallback": "Disabled",
20 "[git-commit]": {
21 "editor.wordWrap": "wordWrapColumn",
22 "editor.wordWrapColumn": 72
24 "[c]": {
25 "editor.detectIndentation": false,
26 "editor.insertSpaces": false,
27 "editor.tabSize": 8,
28 "editor.wordWrap": "wordWrapColumn",
29 "editor.wordWrapColumn": 80,
30 "files.trimTrailingWhitespace": true
32 "files.associations": {
33 "*.h": "c",
34 "*.c": "c"
36 "cSpell.ignorePaths": [
38 "cSpell.words": [
39 "DATAW",
40 "DBCACHED",
41 "DFCHECK",
42 "DTYPE",
43 "Hamano",
44 "HCAST",
45 "HEXSZ",
46 "HKEY",
47 "HKLM",
48 "IFGITLINK",
49 "IFINVALID",
50 "ISBROKEN",
51 "ISGITLINK",
52 "ISSYMREF",
53 "Junio",
54 "LPDWORD",
55 "LPPROC",
56 "LPWSTR",
57 "MSVCRT",
58 "NOARG",
59 "NOCOMPLETE",
60 "NOINHERIT",
61 "RENORMALIZE",
62 "STARTF",
63 "STARTUPINFOEXW",
64 "Schindelin",
65 "UCRT",
66 "YESNO",
67 "argcp",
68 "beginthreadex",
69 "committish",
70 "contentp",
71 "cpath",
72 "cpidx",
73 "ctim",
74 "dequote",
75 "envw",
76 "ewah",
77 "fdata",
78 "fherr",
79 "fhin",
80 "fhout",
81 "fragp",
82 "fsmonitor",
83 "hnsec",
84 "idents",
85 "includeif",
86 "interpr",
87 "iprog",
88 "isexe",
89 "iskeychar",
90 "kompare",
91 "mksnpath",
92 "mktag",
93 "mktree",
94 "mmblob",
95 "mmbuffer",
96 "mmfile",
97 "noenv",
98 "nparents",
99 "ntpath",
100 "ondisk",
101 "ooid",
102 "oplen",
103 "osdl",
104 "pnew",
105 "pold",
106 "ppinfo",
107 "pushf",
108 "pushv",
109 "rawsz",
110 "rebasing",
111 "reencode",
112 "repo",
113 "rerere",
114 "scld",
115 "sharedrepo",
116 "spawnv",
117 "spawnve",
118 "spawnvpe",
119 "strdup'ing",
120 "submodule",
121 "submodules",
122 "topath",
123 "topo",
124 "tpatch",
125 "unexecutable",
126 "unhide",
127 "unkc",
128 "unkv",
129 "unmark",
130 "unmatch",
131 "unsets",
132 "unshown",
133 "untracked",
134 "untrackedcache",
135 "unuse",
136 "upos",
137 "uval",
138 "vreportf",
139 "wargs",
140 "wargv",
141 "wbuffer",
142 "wcmd",
143 "wcsnicmp",
144 "wcstoutfdup",
145 "wdeltaenv",
146 "wdir",
147 "wenv",
148 "wenvblk",
149 "wenvcmp",
150 "wenviron",
151 "wenvpos",
152 "wenvsz",
153 "wfile",
154 "wfilename",
155 "wfopen",
156 "wfreopen",
157 "wfullpath",
158 "which'll",
159 "wlink",
160 "wmain",
161 "wmkdir",
162 "wmktemp",
163 "wnewpath",
164 "wotype",
165 "wpath",
166 "wpathname",
167 "wpgmptr",
168 "wpnew",
169 "wpointer",
170 "wpold",
171 "wpos",
172 "wputenv",
173 "wrmdir",
174 "wship",
175 "wtarget",
176 "wtemplate",
177 "wunlink",
178 "xcalloc",
179 "xgetcwd",
180 "xmallocz",
181 "xmemdupz",
182 "xmmap",
183 "xopts",
184 "xrealloc",
185 "xsnprintf",
186 "xutftowcs",
187 "xutftowcsn",
188 "xwcstoutf"
190 "cSpell.ignoreRegExpList": [
191 "\\\"(DIRC|FSMN|REUC|UNTR)\\\"",
192 "\\\\u[0-9a-fA-Fx]{4}\\b",
193 "\\b(filfre|frotz|xyzzy)\\b",
194 "\\bCMIT_FMT_DEFAULT\\b",
195 "\\bde-munge\\b",
196 "\\bGET_OID_DISAMBIGUATORS\\b",
197 "\\bHASH_RENORMALIZE\\b",
198 "\\bTREESAMEness\\b",
199 "\\bUSE_STDEV\\b",
200 "\\Wchar *\\*\\W*utfs\\W",
201 "cURL's",
202 "nedmalloc'ed",
203 "ntifs\\.h",
207 die "Could not write settings.json"
209 # Infer some setup-specific locations/names
211 GCCPATH="$(which gcc)"
212 GDBPATH="$(which gdb)"
213 MAKECOMMAND="make -j5 DEVELOPER=1"
214 OSNAME=
216 case "$(uname -s)" in
217 MINGW*)
218 GCCPATH="$(cygpath -am "$GCCPATH")"
219 GDBPATH="$(cygpath -am "$GDBPATH")"
220 MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe"
221 MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\""
222 OSNAME=Win32
223 X=.exe
225 Linux)
226 OSNAME=Linux
228 Darwin)
229 OSNAME=macOS
231 esac
233 # Default build task
235 cat >.vscode/tasks.json.new <<EOF ||
237 // See https://go.microsoft.com/fwlink/?LinkId=733558
238 // for the documentation about the tasks.json format
239 "version": "2.0.0",
240 "tasks": [
242 "label": "make",
243 "type": "shell",
244 "command": "$MAKECOMMAND",
245 "group": {
246 "kind": "build",
247 "isDefault": true
253 die "Could not install default build task"
255 # Debugger settings
257 cat >.vscode/launch.json.new <<EOF ||
259 // Use IntelliSense to learn about possible attributes.
260 // Hover to view descriptions of existing attributes.
261 // For more information, visit:
262 // https://go.microsoft.com/fwlink/?linkid=830387
263 "version": "0.2.0",
264 "configurations": [
266 "name": "(gdb) Launch",
267 "type": "cppdbg",
268 "request": "launch",
269 "program": "\${workspaceFolder}/git$X",
270 "args": [],
271 "stopAtEntry": false,
272 "cwd": "\${workspaceFolder}",
273 "environment": [],
274 "MIMode": "gdb",
275 "miDebuggerPath": "$GDBPATH",
276 "setupCommands": [
278 "description": "Enable pretty-printing for gdb",
279 "text": "-enable-pretty-printing",
280 "ignoreFailures": true
287 die "Could not write launch configuration"
289 # C/C++ extension settings
291 make -f - OSNAME=$OSNAME GCCPATH="$GCCPATH" vscode-init \
292 >.vscode/c_cpp_properties.json <<\EOF ||
293 include Makefile
295 vscode-init:
296 @mkdir -p .vscode && \
297 incs= && defs= && \
298 for e in $(ALL_CFLAGS) \
299 '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
300 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
301 '-DBINDIR="$(bindir_relative_SQ)"' \
302 '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \
303 '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \
304 '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \
305 '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \
306 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
307 '-DCURL_DISABLE_TYPECHECK', \
308 '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
309 '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
310 '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \
311 case "$$e" in \
312 -I.) \
313 incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
314 "" "$$incs")" \
315 ;; \
316 -I/*) \
317 incs="$$(printf '% 16s"%s",\n%s' \
318 "" "$${e#-I}" "$$incs")" \
319 ;; \
320 -I*) \
321 incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \
322 "" "$${e#-I}" "$$incs")" \
323 ;; \
324 -D*) \
325 defs="$$(printf '% 16s"%s",\n%s' \
326 "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \
327 "$$defs")" \
328 ;; \
329 esac; \
330 done && \
331 echo '{' && \
332 echo ' "configurations": [' && \
333 echo ' {' && \
334 echo ' "name": "$(OSNAME)",' && \
335 echo ' "intelliSenseMode": "clang-x64",' && \
336 echo ' "includePath": [' && \
337 echo "$$incs" | sort | sed '$$s/,$$//' && \
338 echo ' ],' && \
339 echo ' "defines": [' && \
340 echo "$$defs" | sort | sed '$$s/,$$//' && \
341 echo ' ],' && \
342 echo ' "browse": {' && \
343 echo ' "limitSymbolsToIncludedHeaders": true,' && \
344 echo ' "databaseFilename": "",' && \
345 echo ' "path": [' && \
346 echo ' "$${workspaceRoot}"' && \
347 echo ' ]' && \
348 echo ' },' && \
349 echo ' "cStandard": "c11",' && \
350 echo ' "cppStandard": "c++17",' && \
351 echo ' "compilerPath": "$(GCCPATH)"' && \
352 echo ' }' && \
353 echo ' ],' && \
354 echo ' "version": 4' && \
355 echo '}'
357 die "Could not write settings for the C/C++ extension"
359 for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json
361 if test -f $file
362 then
363 if git diff --no-index --quiet --exit-code $file $file.new
364 then
365 rm $file.new
366 else
367 printf "The file $file.new has these changes:\n\n"
368 git --no-pager diff --no-index $file $file.new
369 printf "\n\nMaybe \`mv $file.new $file\`?\n\n"
371 else
372 mv $file.new $file
374 done