update vim-prettier
authorAJ ONeal <aj@therootcompany.com>
Mon, 15 Mar 2021 19:40:43 +0000 (19:40 +0000)
committerAJ ONeal <aj@therootcompany.com>
Mon, 22 Mar 2021 05:52:50 +0000 (05:52 +0000)
vim-prettier/README.md
vim-prettier/install.sh

index 8c7462aa71a7b65cc7f5afeb835ac3ec2558cec9..f030aaabf59d4cc296605f0b0b9840121510d24d 100644 (file)
@@ -5,11 +5,7 @@ tagline: |
   vim-prettier adds Prettier support for Vim.
 ---
 
-## Updating `vim-prettier`
-
-```bash
-webi vim-prettier
-```
+To update (replacing the current version) run `webi vim-prettier`.
 
 ## Cheat Sheet
 
index addf1d7c1fa025398fdf335920ff4452dea287df..50387ab92b67ee3598a3bfbba64407ffec524e13 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-{
+function __init_vim_prettier() {
     set -e
     set -u
 
 
     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