1

When I run projectile-find-file in GUI (non-terminal) Emacs, the project directory is set to the directory I most recently cd'd to in a terminal window.

Let's say that I have a home directory not under version control, as well as two Git projects, ~/foo and ~/bar. If I do the following

  1. Open a file in ~/foo in Emacs.
  2. Open a terminal window and run cd ~/bar.
  3. Run M-x projectile-find-file.

it will show me the files in ~/bar.

And if I cd to the home directory in iTerm, I get this message:

fatal: Not a git repository (or any of the parent directories): .git

The expected behavior is that it would show the files in ~/foo regardless of what directory was most recently cd'd into.

When I run projectile-project-info, it shows the correct project directory (e.g., Project dir: /Users/pat/foo ## Project VCS: git ## Project type: emacs-cask).

I don't know whether this is a bug or I configured something wrong. It used to work correctly. I'm using Emacs 25.1 and Projectile 20160921.902.

1 Answer 1

2

This problem was caused by a conflict with the Oh My Zsh plugin last-working-dir. Every time you cd to a directory, last-working-dir saves the path to file. When you open a new terminal window, the plug-in sets the current directory to the value in this file.

The problem is that Emacs runs every shell command as though it were in a new terminal window. You can see this effect by enabling last-working-dir and running (message (shell-command "pwd")). If you edit the cache file used by last-working-dir and re-run the previous command, it'll output the updated directory.

I don't know of any way of fixing this other than disabling the last-working-dir.

1
  • Looking at that script, possibly (setenv "ZSH_LAST_WORKING_DIRECTORY" "1") could help?
    – npostavs
    Jan 23, 2017 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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