Skip to content

Show default directory in header-line #1494

Description

@ahmed-shariff

Show the default directory in the header-line.

Examples (see code below for my current implementation):

Image Image

why?
This comes from how I am using gptel-agent and its extensions. I create gptel-buffers and run agent related functionality. Many of the presets I use have elements that are computed based on default-directory (e.g., AGENT.md). Sometimes I go back to a conversation buffer and don't remember where I had created it from, and I end up inspecting default-directory. The proposed design stems from this.

Describe the solution you'd like
The implementation for the above, which just amends the header-line after gptel:

(defun amsha/gptel-use-header-set-dir ()
  "Add the default directory to header."
  (setq header-line-format
        (append 
         `((:eval
            (concat (propertize " " 'display '(space :align-to 0))
                    "{In: "
                    (propertize
                     (pcase-let ((`(,prefix ,project-name ,rel-path ,base)
                                  (shrink-path-file-mixed
                                   (project-root (project-current))
                                   (file-name-directory (directory-file-name default-directory))
                                   (file-name-nondirectory (directory-file-name default-directory)))))
                       (if (string-equal project-name base)
                           (concat prefix project-name)
                         (concat prefix project-name (shrink-path--dirs-internal rel-path 'truncate-all) base)))
                     'face 'dired-directory)
                    "}  ")))
         header-line-format)))

(advice-add 'gptel-use-header-line :after #'amsha/gptel-use-header-set-dir)

Describe alternatives you've considered
I dont use gptel-agent command directly for 2 reasons: (1) I don't want the agent to run from the root always (2) I have other agent definitions I use more than the one shipped with gptel-agent. Most of the time I use inline presets to invoke an agent. I did consider adding the name to the buffer-name, I felt the mode-lines is more easier for me to keep track of that info.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions