@@ -657,21 +657,60 @@ A possible application of this function is in combination with `find-file`:
657
657
` ` `
658
658
This method does not work on remote machines.
659
659
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
+
660
698
# ## When evil-mode is enabled, the cursor moves back in normal state, and this messes directory tracking
661
699
662
700
` evil-collection` provides a solution for this problem. If you do not want to
663
701
use ` evil-collection` , you can add the following code:
702
+
664
703
` ` ` emacs-lisp
665
704
(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))
670
709
671
710
(add-hook ' vterm-mode-hook #' evil-collection-vterm-escape-stay)
672
711
` ` `
673
712
674
-
713
+
675
714
# # Related packages
676
715
677
716
- [vterm-toggle](https://github.com/jixiuf/vterm-toggle): Toggles between a
0 commit comments