Skip to main content
edited tags
Link
Braiam
  • 36.9k
  • 29
  • 114
  • 176
added 4 characters in body
Source Link
Amelio Vazquez-Reina
  • 43k
  • 81
  • 211
  • 298

Not a long time ago, I found the following precious snippet that allows Emacs to track my current directory on any ansi-term buffer.

More specifically, if I cd <some/path> from within a terminal inside Emacs, and I then press C-x C-f, Emacs will run find-file directly from <some/path> directly, which is very, very handy.

if [ -n "$INSIDE_EMACS" ]; then
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi

However, the above trick doesn't work if I ssh to a remote machine from the shell. Ideally in this case, if I pressedpress C-x C-f Emacs should recognize that I have sshed to the rightsome machine, and use tramp to run find-file on the corresponding machine and remote path.

This takes me to the following two questions:

  1. How and why does the snippet above work?
  2. How can I extend it so that it can also track my remote paths after I ssh into another machine?

Not a long time, I found the following precious snippet that allows Emacs to track my current directory on any ansi-term buffer.

More specifically, if I cd <some/path> from within a terminal inside Emacs, and I press C-x C-f, Emacs will run find-file directly from <some/path> directly, which is very, very handy.

if [ -n "$INSIDE_EMACS" ]; then
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi

However, the above trick doesn't work if I ssh to a remote machine from the shell. Ideally, if I pressed C-x C-f Emacs should recognize that I have sshed to the right machine, and use tramp to run find-file on the corresponding remote path.

This takes me to the following two questions:

  1. How and why does the snippet above work?
  2. How can I extend it so that it can also track my remote paths after I ssh into another machine?

Not a long time ago, I found the following precious snippet that allows Emacs to track my current directory on any ansi-term buffer.

More specifically, if I cd <some/path> from within a terminal inside Emacs, and I then press C-x C-f, Emacs will run find-file from <some/path> directly, which is very, very handy.

if [ -n "$INSIDE_EMACS" ]; then
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi

However, the above trick doesn't work if I ssh to a remote machine from the shell. Ideally in this case, if I press C-x C-f Emacs should recognize that I have sshed to some machine, and use tramp to run find-file on the corresponding machine and remote path.

This takes me to the following two questions:

  1. How and why does the snippet above work?
  2. How can I extend it so that it can also track my remote paths after I ssh into another machine?
Tweeted twitter.com/#!/StackUnix/status/460381666188746752
Source Link
Amelio Vazquez-Reina
  • 43k
  • 81
  • 211
  • 298

Tracking my shell path in Emacs

Not a long time, I found the following precious snippet that allows Emacs to track my current directory on any ansi-term buffer.

More specifically, if I cd <some/path> from within a terminal inside Emacs, and I press C-x C-f, Emacs will run find-file directly from <some/path> directly, which is very, very handy.

if [ -n "$INSIDE_EMACS" ]; then
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi

However, the above trick doesn't work if I ssh to a remote machine from the shell. Ideally, if I pressed C-x C-f Emacs should recognize that I have sshed to the right machine, and use tramp to run find-file on the corresponding remote path.

This takes me to the following two questions:

  1. How and why does the snippet above work?
  2. How can I extend it so that it can also track my remote paths after I ssh into another machine?