Add custom commands to the Mac OS X Terminal

When I use my Mac and type away in the Terminal, I've felt the need to add custom commands; e.g. launch an application with that folder/file as a parameter. The way to accomplish this is to create a hidden file in your user folder (i.e. Users/robertnyman) named .profile (you use the dot before the name to create a hidden file in Mac OS X). In that file, you just simply add your commands. Here's an example where I've added three commands to launch Preview, Photoshop and Firefox respectively with the current folder/a file as the input parameter:

prev(){
    open -a /Applications/Preview.app/ "$1"
}

ps(){
    open -a /Applications/Adobe\ Photoshop\ CS/Adobe\ Photoshop\ CS.app/ "$1"
}

ff(){
    open -a /Applications/Firefox.app/ "$1"
}
One of the power features with the code above is that when the prev command is called for a folder, it will open all images in that folder and its sub-folders in the same Preview window. So, happy customizing of commands! :-)

Bonus code: case-insensitive auto-completion

When you press the Tab key in Terminal, you auto-complete the current word you're typing (according to available commands/files). However, this is case-sensitive, which is a bit of an annoyance since many default folders in Mac OS X are named with upper-case starting letters, such as Desktop, Pictures, Movies etc. But, come to the rescue, a simple command to run in the Terminal to make it case-insensitive: echo "set completion-ignore-case On" >> ~/.inputrc Tip: remember to close the Terminal window and restart it before you try it.
Posted in Apple/Mac,Technology |

22 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>