簡體   English   中英

使用cwd從終端啟動emacs時啟動eshell

[英]Launching eshell when starting up emacs from terminal with cwd

我在init.el上添加了一個鈎子來在eshell上啟動Emacs。

;;start on eshell
(add-hook 'emacs-startup-hook 'eshell)

問題是,我經常從終端啟動Emacs,並希望將eshell工作目錄作為我啟動Emacs的終端的工作目錄。

假設我在目錄X中,並啟動Emacs

~/X $ emacs

我希望這發生

Welcome to the Emacs shell
~/X $ 

現在,我補充道

(cd "~")

到我的init.el ,作為臨時解決方案(將emacs路徑更改為home),但這還不夠好。

編輯

我想在它的gui中運行Emacs。

編輯2

如果不使用open -a emacs來啟動應用程序,Chris的答案open -a emacs用了。 但只是改為使用可執行路徑。

當函數display-graphic-p返回nil ,您可以檢測到Emacs正在終端中運行,您可以從default-directory變量獲取從中調用Emacs default-directory

所以像

(when (not (display-graphic-p))
  (cd default-directory)
  (eshell))

在您的init中應該更改為“當前”目錄,然后在從終端調用Emacs時啟動eshell

如果你總是希望調用eshell你應該能夠從代碼中刪除(eshell)並簡單地保留你的emacs-startup-hook

編輯:替換變量window-system ,調用函數display-graphic-p本答案中所建議的那樣。

編輯2:如果您只是想修改emacs-startup-hook以更改為從您調用Emacs的任何目錄,然后啟動eshell (無論窗口系統如何),您可以使用類似的東西

(add-hook 'emacs-startup-hook
          (lambda ()
            (cd default-directory)
            (eshell)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM