summaryrefslogtreecommitdiffstats
path: root/assets/create.sh
blob: 3fb63ebf945abea8db626d8dc0ae266e65075bdd (plain)
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
#!/bin/bash
set -euo pipefail

ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_DIR="$ASSET_DIR/.."

# Ensure submodules are initialized.
function update_submodules() {
	local submodule
	local submodule_prompt=unspecified
	local submodule_path

	{
		while { read -r submodule && read -r submodule_path; } <&3; do
			if ! [[ -d "${REPO_DIR}/.git/modules/${submodule}" ]] && [[ -d "${REPO_DIR}/${submodule_path}" ]]; then
				if [[ "$submodule_prompt" = "unspecified" ]]; then
					echo "One or more submodules were found to be uninitialized."
					printf "Initialize and update them? [Y/n] "
					read -r submodule_prompt
				fi

				case "$submodule_prompt" in
					y|yes|'') {
						git -C "$REPO_DIR" submodule update --init "$submodule_path"
					};;
					n|no) {
						return
					};;
					*) {
						echo "Unknown answer. Not updating submodules."
					};;
				esac
			fi
		done
	} 3< <(git config --file "${REPO_DIR}/.gitmodules" --null --get-regexp path | xargs -0 printf "%s\n" | sed 's/^submodule.//;s/.path$//')
}

if [ -t 0 ]; then
	update_submodules
fi

# Always remove the local cache to avoid any confusion
bat cache --clear

# TODO: Remove this (and the reverse part below) when
# https://github.com/trishume/syntect/issues/222 has been fixed
JAVADOC_FILE="${ASSET_DIR}/syntaxes/01_Packages/Java/JavaDoc.sublime-syntax"
JAVADOC_PATCH="${ASSET_DIR}/JavaDoc.sublime-syntax.patch"
patch "$JAVADOC_FILE" "$JAVADOC_PATCH"

bat cache --build --blank --source="$ASSET_DIR" --target="$ASSET_DIR"

patch -R "$JAVADOC_FILE" "$JAVADOC_PATCH"