Wednesday, December 4, 2019

The end of 2019!

Wow, I felt like this year went bye so quickly. Life has a way of throwing everything at you that can't be compared to anything else I know. Still, I'm excited to see what 2020 has in store for us all!

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"
}

Hope it helps inspire or at least open documents quicker! If you have another app you prefer to use for text editing, you can change the "TextMate.app" to your preferred editor! Happy 2019 everyone, see you next year! 

No comments: