Open remote file while in emacs ansi-term buffer/window: ansi-term + tramp


Vinh Nguyen


June 9, 2009

In emacs, I can edit files remotely using tramp. While ssh'd to a remote server in ansi-term at a specific location, I can open the remote files in emacs as if that remote location is my working directory. This is taken form here. Put the following in the remote server's .bashrc file:

## Emacs: ansi-term + tramp integration
## in ansi-term, ssh to this remote computer, can do C-x C-f and find file in REMOTE working directory
#Emacs ansi-term directory tracking
# track directory, username, and cwd for remote logons
if [ $TERM = eterm-color ]; then
 function eterm-set-cwd {
 echo -e "\033AnSiTc" $(pwd)

 # set hostname, user, and cwd
 function eterm-reset {
 echo -e "\033AnSiTu" $(whoami)
 echo -e "\033AnSiTc" $(pwd)
 echo -e "\033AnSiTh" $(hostname)

 for temp in cd pushd popd; do
 alias $temp="eterm-set-cwd $temp"

 # set hostname, user, and cwd now

For SunOS servers, /usr/ucb is not in path, and whoami is not found. I need to put /usr/ucb in PATH in my .bashrc file. Credit belongs to this thread. Now while ssh'd to a remote server in ansi-term, try C-x C-f, and see the working directory on the remote server available by default.