Continuing on the topic of using Text Filters in BBEdit as discussed in Clean Up XML Formatting in BBEdit, this hint shows you how to clean up shell scripts.
First download bashbeautify.py from the linked github project.
Create a simple bash script that calls the bashbeautify.py file. The following script uses the
--tab-str option to set the default tab character from the script’s default of two spaces to the actual tab character. The
--tab-size option sets how many
--tab-strs per tab. The trailing
- says to act on stdin which is what the open BBEdit file is. Save the Text Filter script to
~/Library/Application Support/BBEdit/Text Filters/bashbeautify.sh to make it available to BBEdit
#!/bin/bash python ~/Applications/bin/bashbeautify.py --tab-str ' ' --tab-size 1 -
Now open a poorly formatted shell script. You may want to remove all indentations first to have a baseline of no indents. You can accomplish this by selecting all (Command-a) and using Command-[ until all text has shifted left. Then use the menu Text > Apply Text Filter > bashbeautify.
Example: This hard to read script
turns into this