@@ -657,21 +657,60 @@ A possible application of this function is in combination with `find-file`:
657657` ` `
658658This method does not work on remote machines.
659659
660+ # ## How can I get the directory tracking in a more understandable way?
661+
662+ If you looked at the reccomended way to set-up directory tracking, you will have
663+ noticed that it requires printing obscure code like ` \e ]2; %m:%2~\a ` (unless you
664+ are using ` fish` ).
665+
666+ There is another way to achieve this behavior. Define a shell function, on a
667+ local host you can simply use
668+
669+ ` ` ` sh
670+ vterm_set_directory () {
671+ vterm_cmd update-pwd " $PWD /"
672+ }
673+ ` ` `
674+ On a remote one, use instead
675+ ` ` ` sh
676+ vterm_set_directory () {
677+ vterm_cmd update-pwd " /-:" " $USER " " @" " $HOSTNAME " " :" " $PWD /"
678+ }
679+ ` ` `
680+ Then, for ` zsh` , add this function to the ` chpwd` hook:
681+
682+ ` ` ` sh
683+ autoload -U add-zsh-hook
684+ add-zsh-hook -Uz chpwd (){ vterm_set_directory }
685+ ` ` `
686+ For ` bash` , append it to the prompt:
687+
688+ ` ` ` sh
689+ PROMPT_COMMAND=" $PROMPT_COMMAND ;vterm_set_directory"
690+ ` ` `
691+ Finally, add ` update-pwd` to the list of commands that Emacs
692+ is allowed to execute from vterm:
693+
694+ ` ` ` emacs-lisp
695+ (add-to-list ' vterm-eval-cmds ' (" update-pwd" (lambda (path) (setq default-directory path))))
696+ ` ` `
697+
660698# ## When evil-mode is enabled, the cursor moves back in normal state, and this messes directory tracking
661699
662700` evil-collection` provides a solution for this problem. If you do not want to
663701use ` evil-collection` , you can add the following code:
702+
664703` ` ` emacs-lisp
665704(defun evil-collection-vterm-escape-stay ()
666- " Go back to normal state but don't move cursor backwards.
667- Moving cursor backwards is the default vim behavior but
668- it is not appropriate in some cases like terminals."
669- (setq-local evil-move-cursor-back nil))
705+ " Go back to normal state but don't move
706+ cursor backwards. Moving cursor backwards is the default vim behavior but it is
707+ not appropriate in some cases like terminals."
708+ (setq-local evil-move-cursor-back nil))
670709
671710(add-hook ' vterm-mode-hook #' evil-collection-vterm-escape-stay)
672711` ` `
673712
674-
713+
675714# # Related packages
676715
677716- [vterm-toggle](https://github.com/jixiuf/vterm-toggle): Toggles between a
0 commit comments