1

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
  • 105
  • 1
  • 1
  • 10

5 Answers5

8

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
  • 13,229
  • 13
  • 58
  • 83
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
  • 19,456
  • 5
  • 52
  • 81
0

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

gg=G
DanieleO
  • 446
  • 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
  • 1,913
  • 1
  • 27
  • 50
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