[TxMt] how to concatenate templates ?

Allan Odgaard throw-away-2 at macromates.com
Sun Nov 11 12:23:16 UTC 2007

On 11 Nov 2007, at 13:18, Roberto Saccon wrote:

> thanks, concatenating now works great, but the variables TM_YEAR and
> TM_DATE don't get passed anymore to the template !!

Ah, because they now get set for “cat” rather than “perl”.

So this would be a way to set them for “perl” instead:

    if [[ ! -f "$TM_NEW_FILE" ]]; then
      cat template_in.txt License.txt \
      |TM_YEAR=`date +%Y` TM_DATE=`date +%Y-%m-%d` \
      perl -pe 's/\$\{([^}]*)\}/$ENV{$1}/g' > "$TM_NEW_FILE"

A perhaps simpler approach is to export them (to all commands):

    if [[ ! -f "$TM_NEW_FILE" ]]; then
      export TM_YEAR=`date +%Y`
      export TM_DATE=`date +%Y-%m-%d`
      cat template_in.txt License.txt \
      |perl -pe 's/\$\{([^}]*)\}/$ENV{$1}/g' > "$TM_NEW_FILE"

More information about the textmate mailing list