Open Dired From Shell

I was browsing the interwebs this morning, looking for a way to open a Dired buffer of the current finder window. There is a lot on going the other way, from Emacs to the Finder, but nothing from the Finder to Emacs. I got this from Fortune Datko:

Add this to your shell rc file (in my case, .zshrc):

# open a dired window for the current directoryndired() {n    emacsclient -e "(dired "$PWD")"n}n

Then, assuming that Emacs server is running, type “dired” in the shell, and a Dirednbuffer of that directory opens in the current Emacs frame.

Just out of curiosity, I wondered what typing “emacsclient -c .” would do. It opens a dired buffer in a new frame. I have a shell script called “ec” that starts a new emacs client, but it’s easy to do it with a zsh alias:

alias ec="emacsclient -c -a ''"n

This starts a server if there is not one already, then opens a new client. So, typing ec . should then open a Dired buffer in a new frame.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s