Skip to main content

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 
(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

OP Edit: Here are two issues I found, with workarounds:

  1. This doesn't work for switching to a dired buffer that already exists. Workaround: press g to refresh the buffer.

  2. This causes my shell prompt to get smashed together with the previous, as it might if the output of the previous command didn't contain a newline. (E.g. if my shell prompt is [scott@local]$ , then on switching to a new dired buffer, I would see [scott@local]$ [scott@local]$ . Workaround: add a newline to the beginning of my shell prompt.

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

OP Edit: Here are two issues I found, with workarounds:

  1. This doesn't work for switching to a dired buffer that already exists. Workaround: press g to refresh the buffer.

  2. This causes my shell prompt to get smashed together with the previous, as it might if the output of the previous command didn't contain a newline. (E.g. if my shell prompt is [scott@local]$ , then on switching to a new dired buffer, I would see [scott@local]$ [scott@local]$ . Workaround: add a newline to the beginning of my shell prompt.

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

OP Edit: Here are two issues I found, with workarounds:

  1. This doesn't work for switching to a dired buffer that already exists. Workaround: press g to refresh the buffer.

  2. This causes my shell prompt to get smashed together with the previous, as it might if the output of the previous command didn't contain a newline. (E.g. if my shell prompt is [scott@local]$ , then on switching to a new dired buffer, I would see [scott@local]$ [scott@local]$ . Workaround: add a newline to the beginning of my shell prompt.

At author's request, edited in my comment with a couple workarounds.
Source Link

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

OP Edit: Here are two issues I found, with workarounds:

  1. This doesn't work for switching to a dired buffer that already exists. Workaround: press g to refresh the buffer.

  2. This causes my shell prompt to get smashed together with the previous, as it might if the output of the previous command didn't contain a newline. (E.g. if my shell prompt is [scott@local]$ , then on switching to a new dired buffer, I would see [scott@local]$ [scott@local]$ . Workaround: add a newline to the beginning of my shell prompt.

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory"))) 

OP Edit: Here are two issues I found, with workarounds:

  1. This doesn't work for switching to a dired buffer that already exists. Workaround: press g to refresh the buffer.

  2. This causes my shell prompt to get smashed together with the previous, as it might if the output of the previous command didn't contain a newline. (E.g. if my shell prompt is [scott@local]$ , then on switching to a new dired buffer, I would see [scott@local]$ [scott@local]$ . Workaround: add a newline to the beginning of my shell prompt.

Source Link
Pradhan
  • 2.4k
  • 18
  • 30

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell.

(add-hook 'dired-after-readin-hook (lambda() (unless (get-buffer "dired-synced-shell") (shell "dired-synced-shell")) (process-send-string (get-buffer "dired-synced-shell") (format "cd %s\n" default-directory)) (message "Switched to new directory")))