1

I have Textmate's terminal tools "mate" installed on my computer. I can open existing files from the terminal but cannot create new files. Here's what I get:

> mate mynewfile.txt & 

The file /Users/aging_gorilla/mynewfile.txt does not exist.

So how do I open a new file with mate?

Thanks

I am using Textmate v1.5.11

kwood
  • 9,854
  • 2
  • 28
  • 32
Rohit
  • 5,840
  • 13
  • 42
  • 65

1 Answers1

1

To create a file if it doesn't exist you can use the touch command line tool.

You can modify your command to be:

$ touch mynewfile.txt && mate mynewfile.txt

If you are using bash or something you can save this as a function to make your life easier. Add something like this to your ~/.profile script:

function mymate {
    touch $1 && mate $1
}

If you want to be able to use it with multiple files like the mate command line tool try this:

function mymate {
    for f in $*
    do
        touch $f
    done
    mate $*
}

You can then use these from the command line like so:

$ mynate file.txt
Will
  • 4,585
  • 1
  • 26
  • 48
  • Thanks. I am surprised that mate command allows me to open existing files but it does not let me create new ones. – Rohit Nov 28 '13 at 22:24
  • I use tcsh. How do I set it up so that my mate file.txt works? The current suggestion (obviously) does not work in my .cshrc file. Thanks! – Rohit Nov 28 '13 at 22:25
  • I'm not familiar with `csh`'s syntax sorry. If you are not comfortable porting this to the different shell syntax then a different solution would be to put the bash code in a script file and put the script somewhere in your path (before the real `mate` command.) – Will Nov 28 '13 at 22:36
  • It seems that the porting should be fairly simple, just change `for f in $*` for `foreach f ($*)` and get rid of the `do`. – Will Nov 28 '13 at 22:42
  • scrub that, [apparently csh doesn't support functions](http://stackoverflow.com/q/13916515/1353098). You'll have to write it as a script and add it into your path (ahead of the real `mate` probably). – Will Nov 28 '13 at 23:06
  • Thanks for working on this. I hope Textmate 2 would have this functionality. Until then I will use what you suggest. – Rohit Nov 28 '13 at 23:27
  • For reference here is [a gist](https://gist.github.com/iwillspeak/5744985) from when I had to do pretty much the same thing. – Will Nov 29 '13 at 00:18