Start a New Terminal(urxvt) at Current Buffer's default-directory on Emacs


I have been really enjoying the more concentration workflow qtile, a tiling window manager, brings me, since I started using it a few months ago. I am more focus on the current task now as all the windows I care about are laid out on the same screen.

As I get more used to qtile at every day's work, I noticed that I became more depend on short-life terminal sessions. Sometimes I need to quickly execute some commands on the current buffer on Emacs, such as searching text which having many matches and quit that terminal after I'm done. So I wondered what could be the best way to achieve that.

At first, I think maybe I can bind some keys to qtile, which triggers a handler in Python to get the current directory of the current window, and then open a new terminal based on that directory. The problem is how to get the current directory of any window, so I suspend as there isn't a good way to do that.

A few days later, I realized that I can just open a terminal from inside Emacs, where it's easy to get the current working directory with default-directory. (The idea was inspired by @ztlevi on Emacs China.) And then I found that I don't really have to open a terminal from any windows, but just from Emacs.

With that idea, it didn't take much time to write a command to do that in urxvt, which I also name as urxvt:

(defun urxvt ()
  "Spawn a urxvt instance based on `default-directory' of current buffer."
  (interactive)
  (let ((urxvt "urxvt256c-ml"))
    (start-process urxvt nil urxvt "-cd" (expand-file-name "./"))))

Sometimes it's important to first clear your mind to figure out what exactly you want.


See also

comments powered by Disqus