Ajay Singh
Ajay Singh

Reputation: 135

format the shell script

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.

Upvotes: 4

Views: 28725

Answers (5)

Panway
Panway

Reputation: 111

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

Upvotes: 2

Daniel YC Lin
Daniel YC Lin

Reputation: 16002

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

shfmt -i 2 -w yourscript

Upvotes: 12

phk
phk

Reputation: 2061

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.

Upvotes: 0

Arun Kurian
Arun Kurian

Reputation: 33

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.

Upvotes: 1

DanieleO
DanieleO

Reputation: 472

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

gg=G

Upvotes: 1

Related Questions