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")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
function command_exists() {
|
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() {
|
2023-12-13 18:18:02 +00:00
|
|
|
if command_exists "$1" ;then
|
2019-10-29 21:55:44 +00:00
|
|
|
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
|
|
|
|
2023-12-13 18:18:02 +00:00
|
|
|
# Determine if we should install a command using userspace commands
|
|
|
|
function should_install_user() {
|
|
|
|
if ! command_exists "$1" ;then
|
|
|
|
# Install in userspace if command doesn't exist
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local bin_path=""
|
|
|
|
bin_path="$(which "$1")"
|
|
|
|
|
|
|
|
# Install in user space if it's already installed in a subdir of the user
|
|
|
|
# home dir
|
|
|
|
if [[ ${bin_path}/ = ${HOME}/* ]] ;then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "WARNING: $1 is already installed by the system."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Runs the "right" pip for installing if there is no global package
|
2023-12-13 17:17:39 +00:00
|
|
|
function maybe_pip_install() {
|
2023-12-13 18:18:02 +00:00
|
|
|
# Filter for user path bins
|
|
|
|
local user_bins=()
|
|
|
|
for bin in "$@" ;do
|
|
|
|
if should_install_user "$bin" ;then
|
|
|
|
user_bins+=("$bin")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Short circuit if empty
|
|
|
|
if [ ${#user_bins[@]} -eq 0 ] ;then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if command_exists pipx ;then
|
2023-12-13 17:17:39 +00:00
|
|
|
# Prefer pipx to keep environments isolated
|
2023-12-13 18:26:27 +00:00
|
|
|
pipx install "${user_bins[@]}"
|
2023-12-13 17:17:39 +00:00
|
|
|
else
|
2023-12-13 18:18:02 +00:00
|
|
|
if command_exists pip3 ;then
|
|
|
|
# If pip3 is there, use it to ensure we're using python 3
|
|
|
|
pip3 install --user --upgrade "${user_bins[@]}"
|
2023-12-13 17:17:39 +00:00
|
|
|
else
|
|
|
|
# Use pip and hope for the best
|
2023-12-13 18:18:02 +00:00
|
|
|
pip install --user --upgrade "${user_bins[@]}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Installs npm packages if there is no global package
|
|
|
|
function maybe_npm_install() {
|
|
|
|
# Filter for user path bins
|
|
|
|
local user_bins=()
|
|
|
|
for bin in "$@" ;do
|
|
|
|
if should_install_user "$bin" ;then
|
|
|
|
user_bins+=("$bin")
|
2023-12-13 17:17:39 +00:00
|
|
|
fi
|
2023-12-13 18:18:02 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Short circuit if empty
|
|
|
|
if [ ${#user_bins[@]} -eq 0 ] ;then
|
|
|
|
return
|
2023-12-13 17:17:39 +00:00
|
|
|
fi
|
2023-12-13 18:18:02 +00:00
|
|
|
|
|
|
|
maybe_run npm install -g "${user_bins[@]}"
|
2023-12-13 17:17:39 +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
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_npm_install bash-language-server
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_npm_install pyright
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-06-13 21:59:37 +00:00
|
|
|
maybe_run rustup component add rustfmt rust-analysis rust-src clippy rust-analyzer
|
2023-07-20 18:14:50 +00:00
|
|
|
if ! command_exists rustup ;then
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/rust-lang/rust-analyzer" \
|
|
|
|
--map-system Windows=pc-windows-msvc --map-system Linux=unknown-linux-gnu --map-system Darwin=apple-darwin \
|
|
|
|
--exec "'F={}; gzip -d /tmp/\$F && mv /tmp/\$(echo \$F|sed s/\.gz\$//) ~/bin/rust-analyzer && chmod +x ~/bin/rust-analyzer'" \
|
|
|
|
"rust-analyzer-{arch}-{system}.gz" /tmp/
|
|
|
|
fi
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
if should_install_user gopls ;then
|
|
|
|
export GO111MODULE=on
|
|
|
|
maybe_run go install golang.org/x/tools/gopls@latest
|
|
|
|
fi
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install mypy || echo "WARNING: mypy is py3 only"
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_npm_install csslint
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install vim-vint
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install yamllint
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_npm_install alex write-good
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install proselint
|
2023-05-22 19:13:45 +00:00
|
|
|
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 \
|
2023-06-12 21:40:09 +00:00
|
|
|
--extract-all --exec "'mv /tmp/\$(echo {}|sed s/\.tar\.gz\$//)/golangci-lint ~/bin/'" \
|
2023-06-12 18:07:43 +00:00
|
|
|
"golangci-lint-{version}-{system}-{arch}.tar.gz" /tmp/
|
2023-05-22 19:13:45 +00:00
|
|
|
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-12-13 18:18:02 +00:00
|
|
|
if ! maybe_run lua -e "'require(\"lfs\")'" ;then
|
|
|
|
maybe_run luarocks --local install luafilesystem
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Version pinned to version in pre-commit so we avoid global check
|
2023-06-09 20:20:28 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
if should_install_user hadolint ;then
|
|
|
|
local hadolint_arm64=arm64
|
|
|
|
if [ "$(uname -s)" == "Darwin" ] ;then
|
|
|
|
hadolint_arm64=x86_64
|
|
|
|
fi
|
|
|
|
maybe_run release-gitter --git-url "https://github.com/hadolint/hadolint" \
|
|
|
|
--map-arch aarch64=$hadolint_arm64 \
|
|
|
|
--map-arch arm64=$hadolint_arm64 \
|
|
|
|
--exec "'mv ~/bin/{} ~/bin/hadolint && chmod +x ~/bin/hadolint'" \
|
|
|
|
"hadolint-{system}-{arch}" ~/bin
|
2023-05-22 19:13:45 +00:00
|
|
|
fi
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_npm_install prettier
|
2023-05-22 19:13:45 +00:00
|
|
|
fi
|
2019-10-29 21:55:44 +00:00
|
|
|
|
|
|
|
# Python
|
2023-05-22 19:13:45 +00:00
|
|
|
if want_lang python ;then
|
2023-12-13 18:18:02 +00:00
|
|
|
maybe_pip_install black reorder-python-imports
|
2023-05-22 19:13:45 +00:00
|
|
|
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
|
2023-12-13 18:18:02 +00:00
|
|
|
local stylua_version=0.19.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-12-13 18:18:02 +00:00
|
|
|
--extract-files "stylua" \
|
2023-05-22 19:13:45 +00:00
|
|
|
--map-arch arm64=aarch64 \
|
|
|
|
--map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \
|
2023-12-13 18:18:02 +00:00
|
|
|
--exec "chmod +x ~/bin/stylua" \
|
2023-05-22 19:13:45 +00:00
|
|
|
"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 ""
|
|
|
|
}
|
|
|
|
|
2023-12-08 19:43:05 +00:00
|
|
|
## Debuggers
|
|
|
|
function install_debuggers() {
|
|
|
|
# Python
|
|
|
|
if want_lang python ;then
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install debugpy
|
2023-12-08 19:43:05 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
function main() {
|
2023-12-13 17:17:39 +00:00
|
|
|
maybe_pip_install release-gitter
|
2022-01-10 20:38:43 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
install_language_servers
|
|
|
|
install_linters
|
|
|
|
install_fixers
|
2023-12-08 19:43:05 +00:00
|
|
|
install_debuggers
|
2019-10-30 00:33:14 +00:00
|
|
|
|
2019-10-29 21:55:44 +00:00
|
|
|
echo ""
|
|
|
|
echo "DONE"
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|