Merge pull request #300 from sheerun/shellcheck_build_cleanup

Cleanup `build` syntax a bit, aided by `shellcheck(1)`
This commit is contained in:
CH-DanReif 2018-05-08 10:04:17 -07:00 committed by GitHub
commit 17a69ab565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

47
build
View File

@ -3,41 +3,44 @@
set -E set -E
DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin" DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin"
# shellcheck disable=SC2034
DIRS_BASIC="syntax compiler indent after/syntax after/indent" DIRS_BASIC="syntax compiler indent after/syntax after/indent"
# shellcheck disable=SC2034
DIRS_ALL="syntax indent compiler autoload ftplugin after" DIRS_ALL="syntax indent compiler autoload ftplugin after"
# shellcheck disable=SC2034
DIRS_SYNTAX="syntax indent after/syntax after/indent" DIRS_SYNTAX="syntax indent after/syntax after/indent"
DIRS_JAVASCRIPT="${DIRS} extras" DIRS_JAVASCRIPT="${DIRS} extras"
DIRS_RM="$DIRS_JAVASCRIPT" read -r -a DIRS_RM <<<"$DIRS_JAVASCRIPT"
OUTPUT="" OUTPUT=""
output() { output() {
OUTPUT="$OUTPUT$1" OUTPUT="$OUTPUT$1"
printf -- "$1" echo -n "$1"
} }
download() { download() {
for pack in $1; do for pack in $1; do
path="$(printf "$pack" | cut -d ':' -f 2)" path="$(cut -d ':' -f 2 <<<"$pack")"
dir="tmp/$(printf "$path" | cut -d '/' -f 2)" dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
rm -rf "$dir" rm -rf "$dir"
(mkdir -p "$dir" && curl --silent -L https://codeload.github.com/$path/tar.gz/master | tar -zx -C "$dir" --strip 1 && printf '.') & (mkdir -p "$dir" && curl --silent -L "https://codeload.github.com/$path/tar.gz/master" | tar -zx -C "$dir" --strip 1 && printf '.') &
done done
wait wait
} }
extract() { extract() {
printf "\n" echo
cat config.vim >> tmp/polyglot.vim cat config.vim >> tmp/polyglot.vim
for pack in $1; do for pack in $1; do
name="$(printf "$pack" | cut -d ':' -f 1)" name="$(cut -d ':' -f 1 <<<"$pack")"
path="$(printf "$pack" | cut -d ':' -f 2)" path="$(cut -d ':' -f 2 <<<"$pack")"
dir="tmp/$(printf "$path" | cut -d '/' -f 2)" dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
directories="DIRS$(printf "$pack" | cut -d ':' -f 3)" directories="DIRS$(cut -d ':' -f 3 <<<"$pack")"
subtree="$(printf "$pack" | cut -d ':' -f 4)" subtree="$(cut -d ':' -f 4 <<<"$pack")"
output "- [$name](https://github.com/$path) (" output "- [$name](https://github.com/$path) ("
subdirs="" subdirs=""
@ -58,10 +61,10 @@ extract() {
copy_file "${dir}${subtree}" "${dir}${subtree}/autoload/go/config.vim" "${name}" copy_file "${dir}${subtree}" "${dir}${subtree}/autoload/go/config.vim" "${name}"
fi fi
output "${subdirs##, })\n" output "${subdirs##, })"$'\n'
if (echo "julia coffee-script elixir fish git plantuml scala swift" | fgrep -q "$name"); then if (echo "julia coffee-script elixir fish git plantuml scala swift" | grep -qF "$name"); then
echo "Skipping ftdetect installation of $name" echo "Skipping ftdetect installation of $name" >&2
continue continue
fi fi
@ -82,19 +85,19 @@ EOF
mv tmp/polyglot.vim ftdetect/ mv tmp/polyglot.vim ftdetect/
for pack in $1; do for pack in $1; do
name="$(printf "$pack" | cut -d ':' -f 1)" name="$(cut -d ':' -f 1 <<<"$pack")"
path="$(printf "$pack" | cut -d ':' -f 2)" path="$(cut -d ':' -f 2 <<<"$pack")"
dir="tmp/$(printf "$path" | cut -d '/' -f 2)" dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
subtree="$(printf "$pack" | cut -d ':' -f 4)" subtree="$(cut -d ':' -f 4 <<<"$pack")"
if [ -d "$dir${subtree:-/}plugin" ]; then if [ -d "$dir${subtree:-/}plugin" ]; then
printf "Possible error (plugin directory exists): $path\n" echo "Possible error (plugin directory exists): $path" >&2
fi fi
done done
} }
copy_dir() { copy_dir() {
for file in $(find "$1/$2" -name '*.vim' -o -name '*.vital'); do find "$1/$2" \( -name '*.vim' -o -name '*.vital' \) -print0 | while read -r -d $'\0' file; do
copy_file "$1" "$file" "$3" copy_file "$1" "$file" "$3"
done done
} }
@ -129,7 +132,7 @@ update_readme() {
+2kb +2kb
/## /##
'b,-2c 'b,-2c
$(printf -- "$OUTPUT" | sort) $(echo -n "$OUTPUT" | sort)
. .
w w
q q
@ -253,7 +256,7 @@ PACKS="
" "
rm -rf tmp rm -rf tmp
rm -rf $DIRS_RM rm -rf "${DIRS_RM[@]}"
mkdir tmp mkdir tmp
printf "Downloading packs..." printf "Downloading packs..."