refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / vim-prettier / install.sh
index addf1d7c1fa025398fdf335920ff4452dea287df..a23337ad45685a9de8851456e05ddeaf9bab7e7d 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-{
+function __init_vim_prettier() {
     set -e
     set -u
 
@@ -8,21 +8,35 @@
     rm -rf "$HOME/.vim/pack/plugins/start/vim-prettier"
     git clone --depth=1 https://github.com/prettier/vim-prettier.git "$HOME/.vim/pack/plugins/start/vim-prettier"
 
+    if [ -z "$(command -v node)" ]; then
+        export PATH="$HOME/.local/opt/node/bin:$HOME/.local/bin:${PATH}"
+        webi node
+    fi
     npm install -g prettier@2
 
-    if [ -f "$HOME/.vimrc" ]; then
-        set +e
-        if ! grep 'source.*prettier.vim' -r ~/.vimrc; then
-            mkdir -p ~/.vim/plugin
-            printf '\n" Prettier: reasonable defaults from webinstall.dev/vim-prettier\n' >> ~/.vimrc
-            printf 'source ~/.vim/plugin/prettier.vim\n' >> ~/.vimrc
-        fi
-        set -e
+    if [ ! -f "$HOME/.vimrc" ]; then
+        touch "$HOME/.vimrc"
     fi
 
-    if ! [ -f "$HOME/.vim/plugin/prettier.vim" ]; then
-        mkdir -p ~/.vim/plugin
+    if ! [ -f "$HOME/.vim/plugins/prettier.vim" ]; then
+        mkdir -p ~/.vim/plugins
         WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
-        curl -fsS -o ~/.vim/plugin/prettier.vim "$WEBI_HOST/packages/vim-prettier/prettier.vim"
+        curl -fsSL -o ~/.vim/plugins/prettier.vim "$WEBI_HOST/packages/vim-prettier/prettier.vim"
     fi
+
+    if ! grep 'source.*plugins.prettier.vim' -r ~/.vimrc > /dev/null 2> /dev/null; then
+        set +e
+        mkdir -p ~/.vim/plugins
+        printf '\n" Prettier: reasonable defaults from webinstall.dev/vim-prettier\n' >> ~/.vimrc
+        printf 'source ~/.vim/plugins/prettier.vim\n' >> ~/.vimrc
+        set -e
+        echo ""
+        echo "add ~/.vim/plugins/prettier.vim"
+        echo "updated ~/.vimrc with 'source ~/.vim/plugins/prettier.vim'"
+    fi
+
+    echo ""
+    echo "vim-prettier enabled with reasonable defaults"
 }
+
+__init_vim_prettier