From: AJ ONeal Date: Mon, 29 Mar 2021 21:37:14 +0000 (+0000) Subject: add vim-shfmt X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=d1fc251c5c5b58c0c81a499ebc9e56c96847478d;p=webi-installers%2F.git add vim-shfmt --- diff --git a/vim-shfmt/README.md b/vim-shfmt/README.md new file mode 100644 index 0000000..b4d3737 --- /dev/null +++ b/vim-shfmt/README.md @@ -0,0 +1,57 @@ +--- +title: vim-shfmt +homepage: https://github.com/z0mbix/vim-shfmt +tagline: | + vim-shfmt: a vim plugin for shfmt +--- + +To update (replacing the current version) run `webi vim-shfmt`. + +## Cheat Sheet + +`vim-shfmt` uses [shfmt](https://webinstall.dev/shfmt) to format your `bash` +scripts on save. + +Use `:Shfmt` to run manually (or just save the file with `:w`). + +This plugin comes with reasonable defaults, which install to +`~/vim/plugins/shfmt.vim`: + +```vim +let g:shfmt_extra_args = '-i 4 -sr -ci -s' +let g:shfmt_fmt_on_save = 1 +``` + +### How to install and configure manually + +1. Clone `vim-shfmt` into your `~/.vim/pack/plugins/start`: + + ```bash + mkdir -p ~/.vim/pack/plugins/start/ + git clone --depth=1 https://github.com/CHANGEME/EXAMPLE.git ~/.vim/pack/plugins/start/shfmt + ``` + +2. Create the file `~/.vim/plugins/shfmt.vim`. Add the same contents as + , + which will look something like this: + + ```vim + " ~/.vim/plugins/shfmt.vim + + " 4 indents, space between redirects, indented case statements, simplify + let g:shfmt_extra_args = '-i 4 -sr -ci -s' + let g:shfmt_fmt_on_save = 1 + + " auto run on .sh and .bash files + augroup LocalShell + autocmd! + + autocmd BufWritePre *.sh,*.bash Shfmt + augroup END + ``` + +3. Update `~/.vimrc` to source that plugin: + ```vim + " shfmt: reasonable defaults from webinstall.dev/vim-shfmt + source ~/.vim/plugins/shfmt.vim + ``` diff --git a/vim-shfmt/install.ps1 b/vim-shfmt/install.ps1 new file mode 100644 index 0000000..d889922 --- /dev/null +++ b/vim-shfmt/install.ps1 @@ -0,0 +1,7 @@ +#!/usr/bin/env pwsh + +IF (!(Test-Path -Path "$Env:USERPROFILE\.vim\pack\plugins\start")) { + New-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start" -ItemType Directory -Force +} +Remove-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start\shfmt" -Recurse -ErrorAction Ignore +& git clone --depth=1 https://github.com/z0mbix/vim-shfmt.git "$Env:USERPROFILE\.vim\pack\plugins\start\vim-shfmt" diff --git a/vim-shfmt/install.sh b/vim-shfmt/install.sh new file mode 100644 index 0000000..4f276a2 --- /dev/null +++ b/vim-shfmt/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function __init_vim_shfmt() { + set -e + set -u + + mkdir -p "$HOME/.vim/pack/plugins/start" + rm -rf "$HOME/.vim/pack/plugins/start/shfmt.vim" + git clone --depth=1 https://github.com/z0mbix/vim-shfmt.git "$HOME/.vim/pack/plugins/start/vim-shfmt" + + if [ -z "$(command -v shfmt)" ]; then + export PATH="$HOME/.local/bin:${PATH}" + webi shfmt + fi + + if [ ! -f "$HOME/.vimrc" ]; then + touch "$HOME/.vimrc" + fi + + mkdir -p ~/.vim/plugins + if ! [ -f "$HOME/.vim/plugins/shfmt.vim" ]; then + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + curl -fsSL -o ~/.vim/plugins/shfmt.vim "$WEBI_HOST/packages/vim-shfmt/shfmt.vim" + fi + + if ! grep 'source.*plugins.shfmt.vim' -r ~/.vimrc >/dev/null 2>/dev/null; then + set +e + mkdir -p ~/.vim/plugins + printf '\n" shfmt: reasonable defaults from webinstall.dev/vim-shfmt\n' >> ~/.vimrc + printf 'source ~/.vim/plugins/shfmt.vim\n' >> ~/.vimrc + set -e + echo "" + echo "add ~/.vim/plugins/shfmt.vim" + echo "updated ~/.vimrc with 'source ~/.vim/plugins/shfmt.vim'" + fi + + echo "" + echo "vim-shfmt enabled with reasonable defaults" + +} + +__init_vim_shfmt diff --git a/vim-shfmt/shfmt.vim b/vim-shfmt/shfmt.vim new file mode 100644 index 0000000..23c1096 --- /dev/null +++ b/vim-shfmt/shfmt.vim @@ -0,0 +1,9 @@ +" 4 indents, Space between redirects, Indented case statements, Simplified +let g:shfmt_extra_args = '-i 4 -sr -ci -s' +let g:shfmt_fmt_on_save = 1 + +augroup LocalShell + autocmd! + + autocmd BufWritePre *.sh,*.bash Shfmt +augroup END