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

2 thoughts on “Clean up shell scripts in BBEdit

  1. Stan Warford says:

    Great tip. Thanks!


  2. I get the result and don’t know how to interpret it.

    usage: [-h] [–tab-str CHAR] [–tab-size TAB]
    FILE [FILE …] error: too few arguments


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: