2018-10-27 Launching terminal in current directory

I am a bit ashamed that I do not always use Eshell – I sometimes rely on a “proper” bash in a terminal. (One possible reason is when I ant to run something that does not play too well with Eshell, like top or watch. I know it is possible to do that in Eshell, using eshell-visual-commands, but it seems I’m too lazy (or still too much accustomed to my usual terminal) to change that.

Anyway, it is feasible to want to run a terminal (or any other program) in the current directory from Emacs. It turns out that it is easy to do using async-shell-command. For instance, if I wanted to run qterminal from Dired, I often just pressed M-& and type qterminal -w `pwd`. (qterminal has a -w option which sets its starting directory.)

After I wrote this, I realized that since pwd seems to output the right directory in this context, maybe it is just because when Emacs runs a shell command, its “current directory” is set up to default-directory (which is Emacs variable holding the buffer’s notion of the current directory, and can be changed using the Emacs cd command). This means that I can just say qterminal to M-&, without all the pwd hassle, and it should just work. And indeed it does.

CategoryEnglish, CategoryBlog, CategoryEmacs