I want that when I choose a project from the list presented by projectile-switch-project, projectile changes the current working directory to the chosen project's root directory.

I tried this:

;; cd into dir i want, including git-root
  (defun cd-dwim ()
      (cd (projectile-project-root)))
  (setq projectile-switch-project-action 'cd-dwim)

Did not work. It projectile-project-root does not receive the new path from the project I just chose.

I'd love if I was able to write something like this:

(setq projectile-switch-project-action 

Is it possible?

  • When you say 'changes the current working directory', what do you want to do with it? open it with dired? cd changes the current buffer's working directory.
    – omajid
    Nov 18 '16 at 20:45
  • I just want that after I invoke projectile-switch-project and chose a project, a later invocation of M-x projectile-find-file will search files inside the root directory of the project I just chose.
    – ninrod
    Nov 18 '16 at 21:25
  • @ninrod It should work as you described without any config. Nov 18 '16 at 23:38
  • @displayname actually without any config, after choosing a project, projectile immediately forces me to chose a file from all the files in the project. If I don't choose a file, then projectile does not switch to the project that I want.
    – ninrod
    Nov 19 '16 at 0:56
  • @ninrod Sorry I misunderstood your needs. I don't know that you even don't want to open a file in project. You should set it to projectile-dired. Or just use the default binding C-c p D. Nov 19 '16 at 3:33

The default action is projectile-find-file. Change it to projectile-dired, and whenever you switch project, you get into a dired buffer of the root of that project:

(setq projectile-switch-project-action 'projectile-dired)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.