当我使用M-x shell打开一个新终端时,它有时会将当前目录设置为该文件。但有时它不会。那么总是在当前目录中打开一个新终端的功能吗?
答案 0 :(得分:3)
ELPA中提供了shell-here
个软件包:M-x list-packages
,查找shell-here
,标记安装(i
)并执行(x
)。< / p>
自述文件的摘录:
Open a shell buffer in (or relative to) default-directory,
e.g. whatever directory the current buffer is in. If you have
find-file-in-project installed, you can also move around relative
to the root of the current project.
I use Emacs shell buffers for everything, and shell-here is great
for getting where you need to quickly. The =find-file-in-project=
integration makes it very easy to manage multiple shells and
maintain your path / history / scrollback when switching between
projects.
github home:https://github.com/ieure/shell-here
我也喜欢shell-pop
,弹出并轻松弹出一个shell缓冲区窗口。 ELPA可能还有更多!
答案 1 :(得分:0)
M-x shell
将切换到现有的shell,如果已经有一个正在运行,这可能是您的问题。如果你不介意创建大量的shell缓冲区,只要找不到访问给定目录的命令,下面的命令就会生成新的缓冲区:
(require 'cl-lib)
(defun shell-at-dir (dir)
"Open a shell at DIR.
If a shell buffer visiting DIR already exists, show that one."
(interactive (list default-directory))
(let ((buf (car (cl-remove-if-not
(lambda (it)
(with-current-buffer it
(and (derived-mode-p 'shell-mode)
(equal default-directory dir))))
(buffer-list)))))
(if buf
(switch-to-buffer buf)
(shell (generate-new-buffer-name "*shell*")))))