BeastieBoy

FreeBSD, Lisp, Emacs, PostgreSQL & co.

Fixing tramp error: "Couldn't find local shell prompt for…"

Fixing tramp error: "Couldn't find local shell prompt for…"

In How this site is made, I explain that I rely on tramp to upload everything to my server after each update to this site. This is convenient, simple, straightforward, transparent (thanks to org mode) and reliable. Well, most of the time. At first, I had a problem where tramp would hang for quite some time and then fail before having uploaded anything, with the message Couldn't find local shell prompt for.... Oh, well… I started looking in the wrong direction: on the server side. I just assumed that since it was hanging there, doing seemingly nothing, for so long, it meant it was happening over the network. Wrong! This had nothing to do with the server and everything to do with my PS1 on my local machine. See, I don't have a regular PS1, I have a prompt over two lines that looks like this:

beastieboy@priest:~/org/beastieboy.net
$

The first line indicate the path, and the second one is the prompt itself. This allows me to display very long paths and keep things readable and consistent, with the prompt always exactly at the same location. Some people say I have an OCD. These people have no taste. Anyway, this two-line prompt is configured in my ~/.kshrc by this line:

PS1='$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'

So, how to handle this? By removing this line, swallowing my pride and resigning myself to a life of sadness, with a measly little one-line prompt? Never. Just add a line below that above and configure good old ksh with a simple PS1 in the specific case tramp is opening a shell:

[ $TERM = "dumb" ] && PS1='$ '

Now, tramp is able to open a shell, parse the prompt and do its work like normal. Glee and happiness! Note though that this doesn't just apply to tramp, but also to all programs using dumb terminals advertised with that specific string; but I haven't seen any problem so far.