Monthly Archives: March 2018

Clean up shell scripts in BBEdit

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 from the linked github project.

Create a simple bash script that calls the 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/ to make it available to BBEdit

python ~/Applications/bin/ --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

Screenshot 2018-03-15 23.10.38

turns into this

Screenshot 2018-03-15 23.10.57

Tagged , , , , , ,