Function: ansi-osc-directory-tracker

ansi-osc-directory-tracker is a byte-compiled function defined in ansi-osc.el.gz.

Signature

(ansi-osc-directory-tracker _ TEXT)

Documentation

Update default-directory from OSC 7 escape sequences.

This function is intended to be included as an element of the list that is the value of ansi-osc-handlers. You should arrange for your shell to print the appropriate escape sequence at each prompt, such as with the following command:

    printf "\\e]7;file://%s%s\\e\\\\" "$HOSTNAME" "$PWD"

A remote default-directory is maintained.

This functionality serves as an alternative to dirtrack-mode(var)/dirtrack-mode(fun) and shell-dirtrack-mode(var)/shell-dirtrack-mode(fun).

Probably introduced at or before Emacs version 31.1.

Aliases

comint-osc-directory-tracker (obsolete since 30.1)

Source Code

;; Defined in /usr/src/emacs/lisp/ansi-osc.el.gz
(defun ansi-osc-directory-tracker (_ text)
  "Update `default-directory' from OSC 7 escape sequences.

This function is intended to be included as an element of the
list that is the value of `ansi-osc-handlers'.  You should arrange
for your shell to print the appropriate escape sequence at each prompt,
such as with the following command:

    printf \"\\e]7;file://%s%s\\e\\\\\" \"$HOSTNAME\" \"$PWD\"

A remote `default-directory' is maintained.

This functionality serves as an alternative to `dirtrack-mode'
and `shell-dirtrack-mode'."
  (when-let* ((url (url-generic-parse-url text))
              ((string= (url-type url) "file")))
    (ignore-errors
      (cd-absolute
       (concat (file-remote-p default-directory)
               (url-unhex-string (url-filename url)))))))