Is there any easy way to open the system command line interface (e.g., cmd
in Windows) at the directory containing the current buffer (if any)? Note that M-x shell
open a command line interface within emacs, hence does not answer the question. I also tried M-x shell-command cmd
but this also open the command line interface within emacs.
1 Answer
You need to use start cmd
to get a new terminal window. Use M-&
(async-shell-command
) to avoid blocking Emacs. This creates a useless *Async Shell Command*
buffer, you can use the start-process-shell-command
function to avoid this:
(start-process-shell-command (format "cmd(%s)" default-directory) nil "start cmd")
-
This gives the desired behaviour only if
default-directory
is not set, because in that case, Emacs seems to resort to using the directory of the buffer you are in. If, however, you did setdefault-directory
, then the terminal will always open in that directory, neglecting the folder you are in. See my answer here if you want the behaviour to be "launch in current folder" even when you have setdefault-directory
. Apr 6, 2021 at 18:23 -
@kotchwane Yeah, Emacs generally considers the value of
default-directory
to be "the folder you are in", by definition. If you changedefault-directory
in a file-visiting buffer, there are two plausible values for "folder you are in", but fixing that is IMO a separate question.– npostavsApr 6, 2021 at 18:49
!
on directory name and thencmd
when prompted for the program to run? I cannot test this on Windows.!
on directory name and thencmd
. Do you mean to doM-!
then givingcmd
?dired
buffer!
is bound todired-do-shell-command
, so pressing it would be similar toM-!
except Emacs automatically sets some parameteres for the command invoked, such as "current directory".