index all rss twitter github linkedin email
Álvaro Ramírez

Álvaro Ramírez

08 October 2015 Change Emacs shell's CWD with helm projectile

If using Emacs shell and helm projectile, you can wire these up to quickly change your current working directory.


(require 'helm-projectile)

(defun ar/shell-cd (dir-path)
"Like shell-pop--cd-to-cwd-shell, but without recentering."
  (unless (string-equal mode-name "Shell")
    (error "Not in Shell mode"))
  (message mode-name)
  (goto-char (point-max))
  (insert (concat "cd " (shell-quote-argument dir-path)))
  (let ((comint-process-echoes t))

(defun ar/helm-projectile-shell-cd ()
  "Change shell current working directory using helm projectile."
  (unless (string-equal mode-name "Shell")
    (error "Not in Shell mode"))
  (let ((helm-dir-source (copy-tree  helm-source-projectile-directories-list)))
    (add-to-list 'helm-dir-source '(action . ar/shell-cd))
    (add-to-list 'helm-dir-source '(keymap . nil))
    (add-to-list 'helm-dir-source '(header-line . "cd to directory..."))
    (helm :sources helm-dir-source
          :buffer "*helm-dirs*"
          :candidate-number-limit 10000)))