Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I currently have a zsh alias setup like so.

alias e="subl"

This lets me e somedir to open up a directory in SublimeText. or e . to open up the current directory.

However, I would like to be able set . to be the default argument, or I can optionally pass in another directory.

So e should expand to subl .

And e somedir should expand to subl somedir

How exactly does one set this up? Is an alias even what I need here?

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

I would use a function:

function e() {
    if [ "$1" != "" ]
    then
        subl $1
    else
        subl .
    fi
}

adding it to .profile

share|improve this answer
6  
+1 for using a function. You can shorten it to: e() { subl "${1:-.}"; } –  glenn jackman Aug 26 '12 at 11:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.