add vim-shfmt

This commit is contained in:
AJ ONeal
2021-03-29 21:37:14 +00:00
parent 82d7d2d05b
commit d1fc251c5c
4 changed files with 115 additions and 0 deletions
+57
View File
@@ -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
<https://github.com/webinstall/webi-installers/blob/master/vim-shfmt/shfmt.vim>,
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
```
+7
View File
@@ -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"
+42
View File
@@ -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
+9
View File
@@ -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