Super Nerdy Cool

My (technical) adventures through the professional world…
June 9, 2009

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

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
## http://www.enigmacurry.com/2008/12/26/emacs-ansi-term-tricks/
#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" done

# set hostname, user, and cwd now eterm-reset fi

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.

1 Comment to “Open remote file while in emacs ansi-term buffer/window: ansi-term + tramp”

Leave a Comment