Mac 最佳应用软件

Generate Markdown table structure with TextExpander (shell script)

No matter how you try and avoid it, sometimes the best way to show something is in a table. Tables look ugly as hell in Markdown, and I always find myself missing the |bits and messing up the table. So I wrote this quickTextExpander shell script snippet in order to generate them. It asks for the number of rows and the number of columns and then generates a table framework you can work inside.

This is a snippet in my TextExpander Writing bundle, which you can subscribe to to quickly get this and some other helpful snippets in your TextExpander.

You could easily modify this to work as an Applescript, etc — just find some other way to define the values of the rows and columns variables. Here’s the code:

#!/bin/bash
rows=%filltext:name=Rows:default=6%
columns=%filltext:name=Columns:default=4%
echo -n "|"
    for i in `seq 1 $columns`
    do
        echo -n -e "\t\t\t|"
    done
echo ""
echo -n "|"
    for i in `seq 1 $columns`
    do
        echo -n -e ":-\t\t\t|"
    done
echo ""
for i in `seq 1 $rows`
do
    echo -n "|"
        for i in `seq 1 $columns`
            do
            echo -n -e "\t\t\t|"
        done
    echo ""
done