refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / vim-prettier / install.sh
1 #!/bin/bash
2
3 function __init_vim_prettier() {
4     set -e
5     set -u
6
7     mkdir -p "$HOME/.vim/pack/plugins/start"
8     rm -rf "$HOME/.vim/pack/plugins/start/vim-prettier"
9     git clone --depth=1 https://github.com/prettier/vim-prettier.git "$HOME/.vim/pack/plugins/start/vim-prettier"
10
11     if [ -z "$(command -v node)" ]; then
12         export PATH="$HOME/.local/opt/node/bin:$HOME/.local/bin:${PATH}"
13         webi node
14     fi
15     npm install -g prettier@2
16
17     if [ ! -f "$HOME/.vimrc" ]; then
18         touch "$HOME/.vimrc"
19     fi
20
21     if ! [ -f "$HOME/.vim/plugins/prettier.vim" ]; then
22         mkdir -p ~/.vim/plugins
23         WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
24         curl -fsSL -o ~/.vim/plugins/prettier.vim "$WEBI_HOST/packages/vim-prettier/prettier.vim"
25     fi
26
27     if ! grep 'source.*plugins.prettier.vim' -r ~/.vimrc > /dev/null 2> /dev/null; then
28         set +e
29         mkdir -p ~/.vim/plugins
30         printf '\n" Prettier: reasonable defaults from webinstall.dev/vim-prettier\n' >> ~/.vimrc
31         printf 'source ~/.vim/plugins/prettier.vim\n' >> ~/.vimrc
32         set -e
33         echo ""
34         echo "add ~/.vim/plugins/prettier.vim"
35         echo "updated ~/.vimrc with 'source ~/.vim/plugins/prettier.vim'"
36     fi
37
38     echo ""
39     echo "vim-prettier enabled with reasonable defaults"
40 }
41
42 __init_vim_prettier