With that, I wanted to share one trick I came up with real quick for the Terminal.app. I'm often navigating my files through the Terminal.app and need a quick way to open up larger files to edit. My choice of plain text editor is TextMate.app and my typical workflow was to "open ." to have the finder show the current folder and then drag the file to TextMate or double click it. Sometimes, depending on the file type association, I could type "open filename" and it would get me to TextMate.app, sometimes not. I started using "open -a TextMate.app filename", but it was repetitive. I could make an alias for "open -a TextMate.app" that would save me some time, but what if I wanted to make a new file and edit it?
The simple function below allows me to type "e filename" and open either a new or existing file. I've added this to my ~/.zprofile so it loads every time I open a shell window:
function e() { # edit existing or new document in textmate
filename="$1"
if [[ ! -e "$filename" ]]; then
touch "$filename"
fi
open -a TextMate.app "$filename"
}
No comments:
Post a Comment