Git Product home page Git Product logo

Comments (5)

minad avatar minad commented on August 20, 2024 1

For shells, I'd provide a hook but not enable it by default. It'll have trouble, with, e.g., SSH and would conflict with "better" ways to set the default directory.

Makes sense. In a shell with ssh one may even want to change the default-directory to a Tramp path.

I currently try out the following function based on your code. I've added it to the manage finish hook. So far it works well.

(defun +exwm-update-default-directory ()
  "Set `default-directory' to the current working directory of the X window process."
  (setq default-directory
        (if-let ((id (exwm--buffer->id (current-buffer)))
                 (response (xcb:+request-unchecked+reply exwm--connection
                               (make-instance 'xcb:ewmh:get-_NET_WM_PID :window id)))
                 (pid (slot-value response 'value))
                 (cwd (file-chase-links (format "/proc/%d/cwd" pid) 1))
                 ((file-accessible-directory-p cwd)))
            (file-name-as-directory cwd)
          (expand-file-name "~/"))))

from exwm.

minad avatar minad commented on August 20, 2024

I've configured EXWM to set the default directory of an X window to the processes default directory and I'm wondering if others would find this behavior useful/desirable.

Sounds like a good idea. Right now I set the default directory to ~/ in all my EXWM buffers, but that's far from ideal.

Of course, this won't keep the default-directory in-sync with the X window, but that usually only matters for shells.

Shells often update the title of the window, so maybe it would work if we refresh the default directory in an exwm-update-title-hook?

How do you suggest to enable this behavior? Install the hooks by default or optionally?

from exwm.

Stebalien avatar Stebalien commented on August 20, 2024

Shells often update the title of the window, so maybe it would work if we refresh the default directory in an exwm-update-title-hook?
How do you suggest to enable this behavior? Install the hooks by default or optionally?

For shells, I'd provide a hook but not enable it by default. It'll have trouble, with, e.g., SSH and would conflict with "better" ways to set the default directory.

As for the initial default directory, I'd set that in manage before calling any hooks. That way the user can easily override it but they get a sane default.

from exwm.

medranocalvo avatar medranocalvo commented on August 20, 2024

It looks like the following can be used to get the CWD on macOS.

(let ((output (process-lines-ignore-status "lsof" "-p" pid "-a" "-d" "cwd" "-Fn")))
  (when output
    (substring (nth 2 output) 1)))

I wonder whether running this process upon exwm-manage--manage-window is sensible.

from exwm.

minad avatar minad commented on August 20, 2024

@medranocalvo Yes, we could do that as a fallback. I don't see a problem, except maybe the efficiency. Starting a process is a bit more expensive than reading a symlink from /proc. Otoh we can also keep things as is. Then the default-directory in exwm-mode buffers on BSD is consistently set to ~/, which is also not that bad.

from exwm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.