3

I have some 1000 lines shell script with all the kepywords

if/else, while, HERE document

Can anyone tell the best way to format the script, so the script looks good.

I was trying VG= in vim but that displaces HERE document content as well.

Ajay Singh
  • 125
  • 1
  • 1
  • 11

5 Answers5

12

check this https://github.com/mvdan/sh, here is the sample command for indent with two spaces

shfmt -i 2 -w yourscript

Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96
1

By default the gg=G gives you 8 tab spaces. To reduce the 8 tab spaces to 3 spaces edit your .vimrc file:

set tabstop=3
set shiftwidth=3
set expandtab

This SO question qives you a good, in context discussion of everything gg=G related.

gboffi
  • 22,939
  • 8
  • 54
  • 85
0

Using VIM add the parameter below in order to indent the entire file

gg=G
DanieleO
  • 462
  • 1
  • 7
  • 20
0

PyCharm's BashSupport plugin now has an experimental bash code formatter.

Sadly the BashSupport plugin "will only receive fixes for major problems" as of 2017.

phk
  • 2,002
  • 1
  • 29
  • 54
0

I found a VSCode plugin based on https://github.com/mvdan/sh , support the .sh .bash Dockerfile .gitignore .properties /etc/hosts ...

Homepage:

https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format

macOS usage:

shift+option+f

or

shift+command+p then type Format Document

Panway
  • 46
  • 4