2019-10-24 19:40:10 +00:00
|
|
|
#! /bin/bash
|
2019-10-29 21:55:44 +00:00
|
|
|
|
2019-11-20 23:19:14 +00:00
|
|
|
# Clear explicit PYTHONPATH since this gets confused between py2 and py3
|
|
|
|
export PYTHONPATH=""
|
|
|
|
|
2023-05-22 19:13:45 +00:00
|
|
|
# Languages to install helpers for
|
|
|
|
declare -a VIM_LANGS
|
|
|
|
|
|
|
|
# Read flag for ignore missing and args for languages
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case "$1" in
|
|
|
|
--ignore-missing)
|
|
|
|
VIM_IGNORE_MISSING=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
VIM_LANGS+=("$1")
|
|
|
|
echo "Read arg $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Langs! ${VIM_LANGS[*]}"
|
|
|
|
|
|
|
|
function want_lang() {
|
|
|
|
if [ "${#VIM_LANGS[@]}" -eq 0 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for l in "${VIM_LANGS[@]}"; do
|
|
|
|
if [ "$l" == "$1" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:25:06 +00:00
|
|
|
# Ignore failed installs
|
2023-05-22 19:13:45 +00:00
|
|
|
if [ -z "$VIM_IGNORE_MISSING" ]; then
|
2021-12-17 19:25:06 +00:00
|
|
|
set -e
|
|
|
|
else
|
|
|
|
set +e
|
|
|
|
fi
|
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Determines if a command exists or not
|
|
|
|
function command_exist() {
|
2021-06-09 17:19:03 +00:00
|
|
|
command -v "$1" > /dev/null 2>&1;
|
2019-10-29 21:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Runs a command or spits out the output
|
|
|
|
function maybe_run() {
|
|
|
|
if command_exist "$1" ;then
|
|
|
|
echo "> $*"
|
2019-11-20 23:19:14 +00:00
|
|
|
# shellcheck disable=2048,2086
|
2019-10-29 21:55:44 +00:00
|
|
|
eval $*
|
|
|
|
else
|
|
|
|
echo "ERROR: $1 does not exist. Could not run $*"
|
|
|
|
fi
|
|
|
|
}
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
## Language servers
|
|
|
|
function install_language_servers() {
|
|
|
|
echo "### Installing language servers..."
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# bash
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang bash ;then
|
|
|
|
maybe_run npm install -g bash-language-server
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Kotlin
|
|
|
|
# https://github.com/fwcd/kotlin-language-server/blob/master/BUILDING.md
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Python
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang python ;then
|
|
|
|
maybe_run npm install -g pyright
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Rust
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang rust ;then
|
|
|
|
maybe_run rustup component add rls rustfmt rust-analysis rust-src clippy rustfmt
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2021-08-24 16:59:12 +00:00
|
|
|
# Go
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang go ;then
|
|
|
|
maybe_run env GO111MODULE=on go install golang.org/x/tools/gopls@latest
|
|
|
|
fi
|
2021-08-24 16:59:12 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
echo ""
|
|
|
|
}
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
## Linters
|
|
|
|
function install_linters() {
|
|
|
|
echo "### Installing linters..."
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Python
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang python ;then
|
|
|
|
maybe_run pip install --user --upgrade flake8
|
|
|
|
maybe_run pip install --user --upgrade mypy || echo "WARNING: mypy is py3 only"
|
|
|
|
maybe_run pip3 install --user --upgrade flake8 mypy
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# CSS
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang css || want_lang web ;then
|
|
|
|
maybe_run npm install -g csslint
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Vim
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang vim || want_lang neovim ;then
|
|
|
|
maybe_run pip install --user --upgrade vim-vint
|
|
|
|
maybe_run pip3 install --user --upgrade vim-vint
|
|
|
|
fi
|
2019-10-29 19:33:08 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# YAML
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang yaml ;then
|
|
|
|
maybe_run pip install --user --upgrade yamllint
|
|
|
|
maybe_run pip3 install --user --upgrade yamllint
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Text / Markdown
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang text || want_lang prose ;then
|
|
|
|
maybe_run npm install -g alex write-good
|
|
|
|
maybe_run pip install --user --upgrade proselint
|
|
|
|
maybe_run pip3 install --user --upgrade proselint
|
|
|
|
fi
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# Makefile
|
2021-12-17 04:51:01 +00:00
|
|
|
# maybe_run go install github.com/mrtazz/checkmake@latest
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2022-01-10 20:39:25 +00:00
|
|
|
# Go
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang go ;then
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/golangci/golangci-lint" \
|
|
|
|
--map-system Windows=windows --map-system Linux=linux --map-system Darwin=darwin \
|
|
|
|
--map-arch x86_64=amd64 --map-arch armv7l=armv7 --map-arch aarch64=arm64 \
|
|
|
|
--extract-files golangci-lint \
|
|
|
|
--exec "'chmod +x ~/bin/golangci-lint'" \
|
|
|
|
"golangci-lint-{version}-{system}-{arch}.tar.gz" ~/bin
|
|
|
|
fi
|
2022-01-10 20:39:25 +00:00
|
|
|
|
2021-11-11 02:03:27 +00:00
|
|
|
# Lua
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang lua || want_lang neovim ;then
|
2023-06-09 20:20:28 +00:00
|
|
|
maybe_run luarocks --local install luafilesystem
|
|
|
|
# Version pinned to version in pre-commit
|
|
|
|
maybe_run luarocks --local install luacheck 1.1.0
|
2023-05-22 19:13:45 +00:00
|
|
|
fi
|
2021-11-11 02:03:27 +00:00
|
|
|
|
2022-01-21 17:21:17 +00:00
|
|
|
# Docker
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang docker ;then
|
|
|
|
hadolint_arm64=arm64
|
|
|
|
if [ "$(uname -s)" == "Darwin" ]; then
|
|
|
|
hadolint_arm64=x86_64
|
|
|
|
fi
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/hadolint/hadolint" \
|
2023-05-23 00:13:17 +00:00
|
|
|
--map-arch aarch64=$hadolint_arm64 \
|
2023-05-22 19:13:45 +00:00
|
|
|
--map-arch arm64=$hadolint_arm64 \
|
|
|
|
--exec "'mv ~/bin/{} ~/bin/hadolint && chmod +x ~/bin/hadolint'" \
|
|
|
|
"hadolint-{system}-{arch}" ~/bin
|
2022-11-02 21:12:54 +00:00
|
|
|
fi
|
2022-11-02 19:30:34 +00:00
|
|
|
|
|
|
|
# Terraform
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang terraform ;then
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/aquasecurity/tfsec" \
|
|
|
|
--map-arch x86_64=amd64 \
|
2023-05-23 00:13:17 +00:00
|
|
|
--map-arch aarch64=arm64 \
|
2023-05-22 19:13:45 +00:00
|
|
|
--map-system Linux=linux --map-system Darwin=darwin \
|
|
|
|
--exec "'mv ~/bin/{} ~/bin/tfsec && chmod +x ~/bin/tfsec'" \
|
|
|
|
"tfsec-{system}-{arch}" ~/bin
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/terraform-linters/tflint" \
|
|
|
|
--map-arch x86_64=amd64 \
|
2023-05-23 00:13:17 +00:00
|
|
|
--map-arch aarch64=arm64 \
|
2023-05-22 19:13:45 +00:00
|
|
|
--map-system Linux=linux --map-system Darwin=darwin \
|
|
|
|
--extract-all --exec "'chmod +x ~/bin/tflint'" \
|
|
|
|
"tflint_{system}_{arch}.zip" ~/bin
|
|
|
|
fi
|
2022-01-21 17:21:17 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
echo ""
|
|
|
|
}
|
2019-10-24 19:40:10 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
## Fixers
|
|
|
|
function install_fixers() {
|
|
|
|
echo "### Installing fixers..."
|
2023-05-22 19:13:45 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
# CSS/JS/HTML/JSON/YAML/Markdown/and more!
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang javascript || want_lang html || want_lang css || want_lang web || want_lang json ;then
|
|
|
|
maybe_run npm install -g prettier
|
|
|
|
fi
|
2019-10-29 21:55:44 +00:00
|
|
|
|
|
|
|
# Python
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang python ;then
|
|
|
|
maybe_run pip install --user --upgrade "'autopep8<1.7.0'" reorder-python-imports
|
|
|
|
maybe_run pip install --user --upgrade autopep8 reorder-python-imports black pyls-black python-lsp-black pyls-isort pyls-mypy || echo "WARNING: black is py3 only"
|
|
|
|
maybe_run pip3 install --user --upgrade black pyls-black python-lsp-black pyls-isort pyls-mypy autopep8 reorder-python-imports
|
|
|
|
fi
|
2019-10-29 21:55:44 +00:00
|
|
|
|
|
|
|
# Rust
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang rust ;then
|
|
|
|
maybe_run rustup component add rustfmt
|
|
|
|
fi
|
2019-10-29 21:55:44 +00:00
|
|
|
|
2021-12-15 17:22:20 +00:00
|
|
|
# Lua
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang lua || want_lang neovim ;then
|
2023-06-09 20:20:28 +00:00
|
|
|
# Version pinned to version in pre-commit
|
|
|
|
local stylua_version=0.17.1
|
2023-05-22 19:13:45 +00:00
|
|
|
if ! release-gitter --git-url "https://github.com/JohnnyMorganz/StyLua" \
|
2023-06-09 20:20:28 +00:00
|
|
|
--version "v$stylua_version" \
|
2023-05-22 19:13:45 +00:00
|
|
|
--map-arch arm64=aarch64 \
|
|
|
|
--map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \
|
|
|
|
--extract-all --exec "chmod +x ~/bin/stylua" \
|
|
|
|
"stylua-{system}-{arch}.zip" ~/bin ; then
|
2023-06-09 20:20:28 +00:00
|
|
|
maybe_run cargo install --version "$stylua_version" stylua
|
2023-05-22 19:13:45 +00:00
|
|
|
fi
|
2022-01-10 20:38:43 +00:00
|
|
|
fi
|
2021-12-15 17:22:20 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
2022-01-10 20:38:43 +00:00
|
|
|
maybe_run pip3 install --user --upgrade release-gitter
|
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
install_language_servers
|
|
|
|
install_linters
|
|
|
|
install_fixers
|
2019-10-30 00:33:14 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
echo ""
|
|
|
|
echo "DONE"
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|