AFAIK there is no easy way to retrieve information from a running process.
But if you want to get the current directory you could:
- ask the shell to print it
- parse and trace the command-line for functions like cd, pushd, popd…
- poll /proc/PID/cwd
The first method is described in the header of term.el
(M-xfind-library
RETterm
RET).
And now, thank you for your question, you gave me the opportunity to do this:
(defadvice term-send-input (after update-current-directory)
(let* ((pid (process-id (get-buffer-process (current-buffer))))
(cwd (file-truename (format "/proc/%d/cwd" pid))))
(cd cwd)))
(ad-activate 'term-send-input)
It's a naive implementation of the third method and it doesn't work if the user uses su
or ssh
. However, I don't know if it's possible withouth using the first or the second method.
In your case, you can just replace the cd
command with whatever you want.