beautysh

raw JSON →
6.4.3 verified Mon Apr 27 auth: no python

A bash beautifier for the masses, providing automated formatting and indentation of shell scripts. Current version is 6.4.3, with regular releases to fix bugs and update dependencies.

pip install beautysh
error beautysh: error: argument files: expected at least one argument
cause No input file was provided to beautysh.
fix
Pass one or more shell script file paths: beautysh script.sh or beautysh *.sh
error ModuleNotFoundError: No module named 'beautysh'
cause The library is not installed or the Python environment is wrong.
fix
Install beautysh with 'pip install beautysh', then ensure you're using the same Python environment.
gotcha beautysh modifies files in-place by default. Ensure you have backups or use the --check flag before formatting.
fix Use beautysh with --check to only verify formatting, or pass --force to overwrite.
gotcha beautysh may not correctly handle shell scripts with unusual syntax (e.g., heredocs with special characters, complex case patterns). Test on your codebase before integrating.
fix Review changed lines after formatting, especially around heredocs and case statements.

Basic usage: format a bash script file using beautysh.

from beautysh import beautysh
import tempfile, os

code = '''if [ -z "$1" ]; then
  echo "No argument"
fi'''
with tempfile.NamedTemporaryFile(mode='w', suffix='.sh', delete=False) as f:
    f.write(code)
    fname = f.name
try:
    result = beautysh(files=[fname])
    print('Formatted successfully')
finally:
    os.unlink(fname)