vterm-toggle icon indicating copy to clipboard operation
vterm-toggle copied to clipboard

`vterm-toggle-cd` not inserting CD command

Open bleggett opened this issue 3 years ago • 6 comments

Maybe this is me not understanding how the package works, but when I invoke vterm-toggle-cd I expect it to bring up a vterm buffer and cd to the location of the last active buffer.

Instead, calling that function inserts ^K into the vterm buffer, like so Screen Shot 2020-07-09 at 12 38 24 PM

after this, manually calling vterm-toggle-insert-cd manually works correctly, but my understanding is that vterm-toggle-cd should be exactly equivalent to manually invokingvterm-toggle and then vterm-toggle-insert-cd - for me it's not.

Am I missing something?

bleggett avatar Jul 09 '20 16:07 bleggett

tell me the value of (vterm--prompt-tracking-enabled-p) and I think you should enable Directory tracking and Prompt tracking https://github.com/akermu/emacs-libvterm#directory-tracking-and-prompt-tracking https://github.com/akermu/emacs-libvterm#shell-side-configuration

or custom term-prompt-regexp, make it match your prompt .

jixiuf avatar Jul 10 '20 15:07 jixiuf

@jixiuf it's nil - and I've properly set up directory and prompt tracking for zsh as per those instructions - I'm on macOS and am using a custom ZSH prompt but I assume that even with a custom prompt the below is all I should need for this to work:


# Added for Emacs libvterm
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)";
}

setopt PROMPT_SUBST
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'

Inside the vterm, this is the value of $PROMPT

/ » echo $PROMPT                                                                                                                                                                                                                     useer@machine
$FG[237]------------------------------------------------------------%{$reset_color%}
$FG[032]%~\
$(git_prompt_info) \
$FG[105]%(!.#.»)%{$reset_color%} %{$(vterm_prompt_end)%}

bleggett avatar Jul 10 '20 19:07 bleggett

it's weird the value of (vterm--prompt-tracking-enabled-p) is nil. does you eval (vterm--prompt-tracking-enabled-p) in vterm buffer.

jixiuf avatar Jul 11 '20 02:07 jixiuf

I have the same problem but without the ^K part. Doing vterm-toggle-cd has exactly the same effect as vterm-toggle.

My workaround is this:

(defun tmalsburg-vterm-toggle-cd-show ()
  (interactive)
  (vterm-toggle-cd-show)
  (vterm-toggle-insert-cd))

(define-key vterm-mode-map [f4] 'tmalsburg-vterm-toggle-cd-show)

tmalsburg avatar Nov 27 '20 17:11 tmalsburg

I had the same issue. (vterm--prompt-tracking-enabled-p) is nil. for me as well.

adouzzy avatar Jul 20 '21 11:07 adouzzy

My experience with vterm-toggle-cd is the following:

  • if no vterms exist, this behaves as documented (new vterm in the right directory)
  • if a vterm exists in a different folder, this toggles it and shows a message about vterm-toggle-insert-cd, but it doesn't insert it automatically.
  • vterm--prompt-tracking-enabled-p is 2 for me

indigoviolet avatar Feb 11 '22 05:02 indigoviolet