Skip to main content
added 1019 characters in body
Source Link
eatloaf
  • 145
  • 5

UPDATE

For posterity, here are the final functions I'm using

(defun wsl/execute ()
  "execute file at point in dired"
  (interactive)
  (dired-do-shell-command
   "cmd.exe /c start \"\""
   current-prefix-arg
   (dired-get-marked-files t t)))

Enter on file to launch it or open it:

(defun wsl-p ()
  "Is the system WSL?"
  (and (eq system-type 'gnu/linux)
       (string-match
        "Linux.*Microsoft.*Linux"
        (shell-command-to-string "uname -a"))))

(defun dired-find-file-or-execute (orig-fun &rest args)
  "Wrapper for dired-find-file that, on WSL, launches binaries instead of opening them"
  (interactive)
  (let ((file (dired-get-marked-files t t)))
    (if
        (and
         (wsl-p)
         (or (string-match-p "\.exe\\'" (first file))
             (string-match-p "\.bat\\'" (first file))
             (string-match-p "\.com\\'" (first file))))
        (dired-do-shell-command "cmd.exe /c start \"\"" current-prefix-arg (dired-get-marked-files t t))
      (apply orig-fun args))))

(advice-add 'dired-find-file :around #'dired-find-file-or-execute)

UPDATE

For posterity, here are the final functions I'm using

(defun wsl/execute ()
  "execute file at point in dired"
  (interactive)
  (dired-do-shell-command
   "cmd.exe /c start \"\""
   current-prefix-arg
   (dired-get-marked-files t t)))

Enter on file to launch it or open it:

(defun wsl-p ()
  "Is the system WSL?"
  (and (eq system-type 'gnu/linux)
       (string-match
        "Linux.*Microsoft.*Linux"
        (shell-command-to-string "uname -a"))))

(defun dired-find-file-or-execute (orig-fun &rest args)
  "Wrapper for dired-find-file that, on WSL, launches binaries instead of opening them"
  (interactive)
  (let ((file (dired-get-marked-files t t)))
    (if
        (and
         (wsl-p)
         (or (string-match-p "\.exe\\'" (first file))
             (string-match-p "\.bat\\'" (first file))
             (string-match-p "\.com\\'" (first file))))
        (dired-do-shell-command "cmd.exe /c start \"\"" current-prefix-arg (dired-get-marked-files t t))
      (apply orig-fun args))))

(advice-add 'dired-find-file :around #'dired-find-file-or-execute)
edited title
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

How can I executeget the name of the file at point in diredon the current Dired line?

edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
added 118 characters in body
Source Link
eatloaf
  • 145
  • 5
Loading
Source Link
eatloaf
  • 145
  • 5
Loading