Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier shell script format

Can I format template literal embedded shell script with Prettier ?

Example:

Before formating:

import {bash} from 'random-bash-runner'

await bash`
a_bash_command argument1 \
     main-dev \
argument4 --database=name --quiet`

After formatting:

import {bash} from 'random-bash-runner'

await bash`
  a_bash_command argument1 \
    main-dev \
    argument4 l \
    --database=name --quiet
`

Thanks

like image 496
Broto Avatar asked Jun 22 '26 10:06

Broto


1 Answers

Most languages have their own fmt command.

Prettier is for web languages that are run by committees and don't have the same kind of leadership pushing forward practical developer tools.

For shell languages use shfmt and shellcheck:

  • shfmt source: https://github.com/mvdan/sh
  • shfmt cheatsheet: https://webinstall.dev/shfmt/
  • vim-shfmt cheatsheet: https://webinstall.dev/vim-shfmt/
  • shellcheck source: https://github.com/koalaman/shellcheck
  • shellcheck cheatsheet: https://webinstall.dev/shellcheck/
  • vim-shellcheck cheatsheet: https://webinstall.dev/shellcheck/

These follow Google's shell style and linting guidelines. Not that Google is perfect, but this is good stuff - it taught me proper shell scripting 10x better in just one year of using them than after 15+ years of doing it here and there without them.

like image 192
coolaj86 Avatar answered Jun 24 '26 23:06

coolaj86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!