The (Unofficial) BBEdit Hints Weblog
2 Ways to make pretty tables in BBEdit

On Twitter, @kaushikgopal inspired me by asking:

@bbedit @bbedit_hints do we have something like Entable baked in to BBEdit? couldn’t get Entable working.

In a previous hint I talked about using the Unix Worksheet, pbpaste, and the column command to create a quick filter. pbpaste is a unix command that says, “use the contents of the clipboard here”.

In in November, I tweeted this example:

For example, a tip from last week, in this format: pbpaste | column -t

Pretty Tables

column -t will take input that looks like this:

| NAME | DOB |
| RYAN WILCOX | MAY 31 |
| HEATHER WILCOX | JAN 3 |
| VIVIENNE WILCOX | JAN 31 |

and make it look like this:

NAME               DOB 
RYAN WILCOX        MAY 31 
HEATHER WILCOX     JAN 3 
VIVIENNE WILCOX    JAN 31 

Which we can agree is much prettier - everything’s spaced out correctly.

Now, there is one problem with that format: there are no separators!

Pretty tables (now with separators!)

Say we want to preserve the |s because the table is really a multimarkdown table (whose format requires tables to have |s along the “borders” of the table.) With plain column -t we lose that important information.

Thanks to a unix.stackexchange question along those same lines, we can use a slightly modified command to get the same results:

pbpaste | sed 's/|/@|/g'  | column -s '@' -t

This sed command adds “@” in front of every | character you have - then column -t looks at the @s, formats the table (removing the @s in the process).

This solves the problem pretty well (assuming your table is not a table full of email addresses :)).

Now, making this into a permanent Text Filter is easy:

  1. Create a new file in your Text Filters folder (~/Library/Application Support/BBEdit/Text Filters/ or ~/Dropbox/Application Support/BBEdit/Text Filters)

  2. Add these two lines:
    #!/bin/sh

    sed 's/|/@|/g' | column -s '@' -t

  3. Save the file and look in your Text Filters list. (You may need to restart BBEdit to get this new filter to show up)

This script will now act as a text filter - taking your selection in, doing an operation to it, and writing out some replacement text.