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 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

bashbeautify.sh

#!/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

Screenshot 2018-03-15 23.10.38

turns into this

Screenshot 2018-03-15 23.10.57

Advertisements
Tagged , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: