Buddy’s Blog | Art, design, code, and business

Jan/08

30

How Tos: Auto Save Copy for TextMate

You might be migrating to TextMate from BBEdit or some other text editors. And used a featured that allowed automatic backup copies for ever file you edit and save and was looking for this feature in Textmate, honestly it doesn’t exist. I found a solution in TextMate’s Wiki that works, quiet well actually, you create a small command in the Bundle Editor:

From TextMate Wiki Main / Howtos – TextMate Wiki

The Setup: Set up a TM_BACKUP_DIR environment variable in the Advanced / Shell Variables section of the TM preferences. Set it to the directory where you’d like your backups to be saved. Use the full path (i.e., /Users/michael/Documents rather than ~/Documents).

Save: Current File

Command(s):

[code lang="bash"]
# Save a copy of this file to the backup directory
THEDATE=`php -r 'print date('Ymd');'`
THETIME=`php -r 'print date('His');'`
mkdir -p "$TM_BACKUP_DIR/$THEDATE"
perl -e 'while () { print $_; }' > "$TM_BACKUP_DIR/$THEDATE/$TM_FILENAME.$THEDATE.$THETIME.backup"
[/code]

Std In: Entire Document

Std Out: Discard

Activation: Key Equivalent Cmd-S

My variation of the script Michael Lehmkuhl posted in the Wiki. I change the directory creation to duplicate the full file path of the current file in the backups folder.

[code lang="bash"]# Save a copy of this file to the backup directory
THEDATE=`php -r 'print date('Ymd');'`
THETIME=`php -r 'print date('His');'`
mkdir -p "$TM_BACKUP_DIR/$TM_DIRECTORY"
perl -e 'while () { print $_; }' > "$TM_BACKUP_DIR/$TM_DIRECTORY/$THEDATE.$THETIME_$TM_FILENAME"[/code]
Share and Enjoy:
  • email
  • Add to favorites
  • Digg
  • del.icio.us
  • LinkedIn
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Facebook
  • MySpace
  • Live
  • Twitter
  • Technorati
  • StumbleUpon

RSS Feed

2 Comments for How Tos: Auto Save Copy for TextMate

Ryan | August 5, 2009 at 12:50 am

Hello,

On line 4 of your script do you mean
mkdir -p “$TM_BACKUP_DIR/$TM_DIRECTORY”
instead of
mkdir -p “$TM_BACKUP_DIR/$TM_DIRECTORY” ?

-Ryan

Ryan | August 5, 2009 at 12:56 am

In my above comment, the ‘b’ tags around $TM_DIRECTORY were not intended to actually make the text bold.

Ironically, that may have been your original intent :)

Leave a comment!

<<

>>