ターミナルエミュレータで起動したemacsで、ターミナルのタイトルを変える

マウスがただひたすらにウザいし、フォント設定をターミナルエミュレータと共有できるのが便利なので、いつもemacsは-nw付きで起動してる。

(defun set-terminal-title (&rest args)
  ""
  (interactive "sString to set as title: ")
  (let ((tty (frame-parameter nil
                                  'tty-type)))
    (when (and tty
               (eq t (compare-strings "xterm" 0 5 tty 0 5)))
      (send-string-to-terminal (apply 'concat
                                      "\033]0;"
                                      `(,@args "\007"))))))
(add-hook 'post-command-hook
          (lambda ()
            (set-terminal-title "emacs "
                                default-directory)))