Sometimes I need to do this kind of manipulation on a remote host using SSH. Could I do this using Emacs? Sure I can!
Emacs is able to handle remote files through SSH. It is a feature shipped with it called Tramp that allows to access remote hosts transparently from within Emacs using various access methods such as SSH, FTP, …
It can do a lot of things, it literally allows to work with remote hosts as if you were working locally. Pure awesomeness, the power of my customized Emacs everywhere.
What happened to me
I decided to give it a try as soon as I got the opportunity. What a disappointment when I saw that opening a remote file was lagging as hell, lagging so much that it always ended up with a timeout.
I googled for my issue and found out that it was working flawlessly for a lot of people.
My immediate thought was “F***ing OS X, that must be your fault!”. I googled more focusing on “OS X” keyword and found some people having the same issue. They were using OS X too.
I did try some of the advices given by people that weren’t experiencing this issue. No luck…
After several hours of research I finally landed on the Tramp FAQ and I saw this:
tramp needs a clean recognizable prompt on the remote host for accurate parsing
I knew it was the source of my issue and felt so lame of not having read the official documentation sooner. My prompts are always fancy and full of info even on my remote servers.
I did try to simplify my prompt and Tramp started to work seamlessly!
So what’s the fix?
Tramp expects a really simple prompt on the remote host to
parse it and detect when a command has finished. Basically it wants a
prompt ending with
>. It’s also having hard time to
parse prompts containing escape sequences for coloring.
My remote prompt was using a feature of ZSH which allow to have a prompt on the right side of the terminal. This was confusing Tramp because it couldn’t find the “magical” character at the end of the line.
There are two solutions to fix this.
The first solution is nice if you can’t change the remote prompt. You
can change a variable in your Emacs config that describes the
regexp used by Tramp to recognize the prompt. This variable
The second solution — the one I chose — is even simpler in my
opinion. Just change the prompt on the remote host. You can add a
condition in your
.zshrc (or whatever the init file of your shell
is) and do something like this:
When Tramp connects to a remote host it sets the
environment variable as
dumb so you know you’re in the situation
were you want a really simple prompt. What to do then is to set the
prompt to a simple “$ “ string.
This way, if I connect on my remote using a real terminal I still have my fancy prompt with all my info, colors, right prompt and everything.
Moral of this story
Adding a single line in my
.zshrc file on my remote server was
enough to solve the problem I was experiencing for months and that
some other users are experiencing for many
years without a single answer.
I can’t tell you enough to always check the official documentation and issues in the tracker of a software / lib / whatever when you’re experiencing an issue. It often gives an answer to your problem and it will avoid some hours lost in reading half of the web.
Hope it helps if you’re digging for the same issue and you’re left without answers until now.