0

I find myself typing these commands a lot (on Mac):

$ touch example.txt
$ open example.txt

I was wondering if there was an easier way to do this. I tried this:

$ alias t='touch $0 && open $0’

But I got this:

$ t awef.txt
touch: illegal option -- b

Note: I do not want to empty the file. If the file already has content, I just want to open it.

rassar
  • 103

1 Answers1

3

Don't use an alias. They are extremely limited and, for example, won't let you interpolate an argument into the definition. Instead, use a function:

t() { [[ ! -f "$1" ]] && touch "$1"; open "$1"; }

This creates (touches) a file only if it doesn't already exist.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287