Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

zsh alias with default argument, but also overridable

Writer Andrew Henderson

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

I would use a function:

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

adding it to .profile

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy