Kayla Skates - Home / Posts

Emacs, Tramp, Dired Mode, Ghostel, and ZMX

When using tmux with emacs, directory changes were not being picked up. Terminals can be notified of the current directory by printing terminal control characters to the screen.

As a workaround I switched to Ghostel,ZMX, and installed a change directory shell hook to tell the terminal when the current directory changes.

Ghosty and zmx was installed on macos by running:

brew install ghostty neurosnap/tap/zmx

In emacs, ghostel was installed for terminal emulation

(use-package ghostel :ensure t)

Then in my ~/.zshrc file, the following hook was installed. *Note: If you use SSH, this zsh script has to be installed on the remote hosts too.

  emacs_chpwd_tracker() {
    # \e]7; specifies the file URL scheme for directory tracking
    # hostname requires wrapping to prevent spaces/special characters
    if [[ -n "$INSIDE_EMACS" ]]; then
        printf "\e]7;file://%s%s\a" "$HOST" "$PWD"
    fi
}

# Safely register the function to the chpwd hook
autoload -U add-zsh-hook
add-zsh-hook chpwd emacs_chpwd_tracker

Leave a Reply

Your email address will not be published. Required fields are marked *