16

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?

1 Answer 1

30

I would use a function:

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

adding it to .profile

2
  • 23
    +1 for using a function. You can shorten it to: e() { subl "${1:-.}"; } Aug 26, 2012 at 11:46
  • This works well but you lose the command completion. Although in this case the default of completing file names isn't bad.
    – Kevin Cox
    May 26, 2015 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .