Open Emacs dired buffer from shell

Lately, I’ve had a falling-out with M-x shell.  There are a few ways to incorporate the shell in Emacs and for the most part, the inferior shell (as it’s called in Emacs) has served me well.  However there are some annoyances and the biggest one for me is that it’s not a *real* terminal.

While I like the idea of eshell, it doesn’t quite cut it as a true shell replacement.  Fortunately with Byobu and zsh, I’ve been quite happy with my shell experience.  Yet sometimes when I’m levels deep in a repository, I just want to oped a dired buffer!  So I added this small shell function to my rc file:

# open a dired window for the current directory
dired() {
    emacsclient -e "(dired \"$PWD\")"

It’s a neat trick (the “-e” option) where you can pass Lisp code to be evaluated instead of opening a file.  This assumes that you are running Emacs as a server.  By the way, using emacsclient -t while in a shell is a way to accomplish “quick” editing.  Since Emacs is running at a daemon, the oft-cited long Emacs start times are no longer an issue.

Update: *Face Palm* original title was “update Emacs dired buffer from dired!” Argh…

One thought on “Open Emacs dired buffer from shell

Comments are closed.