riscy / shx-for-emacs

An Emacs shell-mode (and comint-mode) extension that enables displaying small plots and graphics and lets users write shell commands in Emacs Lisp.
GNU General Public License v3.0
218 stars 10 forks source link

PWD environment variable doesn't change when changing directory in a shx shell #31

Open elkarouh opened 2 years ago

elkarouh commented 2 years ago

When changing directory, i ran the command :eval (getenv "PWD") and it returns the original directory at shell creation. How can i get the current directory when in shx mode?

riscy commented 2 years ago

Hi! There's a builtin command :pwd that will output the default-directory but you can also use :ev default-directory to see the variable's current value.

elkarouh commented 2 years ago

This is the problem. $:pwd does not always return the same result as $pwd I tried :shell-resync-dirs to reset Emacs' pwd to the shell's pwd but it is not recognised. Is it the right syntax?

Fwiw, i use ksh.

Regards

riscy commented 2 years ago

Ah, this is because the builtin shell (from shell.el) has directory tracking that is not always 100% accurate. It can lose track for example if you use unconventional commands to change directories. There's a builtin function shell-resync-dirs that will attempt to set the value of default-directory to the correct value.

One example of this is I use z to hop to directories which of course shell.el can't keep up with. shx has a variable to help out with this a bit -- in the case of z you can (setq shx-directory-tracker-regexp "^z ") and then shx will attempt to run shell-resync-dirs whenever the command matches the given regexp.

Hopefully that helps, but let me know!

riscy commented 2 years ago

I missed the part where you wrote this:

:shell-resync-dirs to reset Emacs' pwd to the shell's pwd but it is not recognised. Is it the right syntax?

If you want to run this command it's bound by default to M-return or M-x shell-resync-dirs -- :shell-resync-dirs won't work.