akermu / emacs-libvterm

Emacs libvterm integration
GNU General Public License v3.0
1.69k stars 135 forks source link

Remote shell tracking - tramp customizations required? update README if reproducible? #369

Open twagtwig opened 4 years ago

twagtwig commented 4 years ago

I have to include the following to get dired-jump, and find-file to correctly start on the remote server (from a vterm buffer already ssh'd-in):

;; required to make tramp directory tracking work correctly
(setq tramp-default-method "ssh")
(setq tramp-shell-prompt-pattern "\\(?:^\\|\r\\)[^]#$%>\n]*#?[]#$%>].* *\\(^[\\[[0-9;]*[a-zA-Z] *\\)*")

I got it from https://github.com/akermu/emacs-libvterm/issues/55#issuecomment-472255904 The remote server is Debian 10 cloud.

Can anyone confirm that setting tramp-shell-prompt-pattern is necessary to connect to a remote server with the full shellside configuration from the README?

For reference, here's what I have in my shell on the server:

# https://github.com/akermu/emacs-libvterm
function vterm_printf(){
    if [ -n "$TMUX" ]; then
        # Tell tmux to pass the escape sequences through
        # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
        printf "\ePtmux;\e\e]%s\007\e\\" "$1"
    elif [ "${TERM%%-*}" = "screen" ]; then
        # GNU screen (screen, screen-256color, screen-256color-bce)
        printf "\eP\e]%s\007\e\\" "$1"
    else
        printf "\e]%s\e\\" "$1"
    fi
}

vterm_prompt_end(){
    vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
}
PS1=$PS1'\[$(vterm_prompt_end)\]'

If this is the case, I suggest including something about it in the README.

This is in the spirit of https://github.com/akermu/emacs-libvterm/issues/237

More comprehensive documentation: I am not even sure if the documentation covers all the features available in the package for the end user, let alone for developers.

A sentence in the https://github.com/akermu/emacs-libvterm#directory-tracking-and-prompt-tracking section like:

If TRAMP is not correctly configured to understand the custom vterm prompt on remote machines, you may have errors like

File error: Tramp failed to connect.  If this happens repeatedly, try
‘M-x tramp-cleanup-this-connection’

when you try to find-file or dired-jump from a vterm buffer. This should solve the problem:

(setq tramp-shell-prompt-pattern "\\(?:^\\|\r\\)[^]#$%>\n]*#?[]#$%>].* *\\(^[\\[[0-9;]*[a-zA-Z] *\\)*")
Sbozzolo commented 4 years ago

I have at the beginning of my remote .rc file the following lines:

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

So the rest of the file is not evaluated and the prompt stays extremely simple.

However, this problem caused multiple headaches to me and to people I know (not necessarily with vterm), so I'll add a note in the README.

twagtwig commented 4 years ago

Thank you @Sbozzolo , I have that line too in my .bashrc on the server but after some testing it doesn't have any effect on TRAMP for me. I still got errors like:

Tramp: Waiting for prompts from remote shell...failed
Tramp: Opening connection for root@server using ssh...failed

The only thing that worked for me is

A

In emacs: (setq tramp-shell-prompt-pattern "\\(?:^\\|\r\\)[^]#$%>\n]*#?[]#$%>].* *\\(^[\\[[0-9;]*[a-zA-Z] *\\)*")

B

In .bashrc on the remote server:

vterm_prompt_end(){
    vterm_printf "51;Auser@server:$(pwd)"
}

(Where I replace "user" and "server" with the terms ssh is expecting from my local .ssh/config. Using $(whoami)@$(hostname) didn't work for me because I use an alias in my ssh config.