歡迎您光臨本站 註冊首頁

邪惡的 eshell

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  

 對於一個經常“被跨平台”的人來說,Windows 下沒有一個好用的 shell,不能不說是一個 遺憾。

雖然說 bash zsh 都有 windows 的版本,但幾乎一無是處……此處暫省略1000字,且不說應有 盡沒的功能,光是那速度就讓人抓狂,動不動裝死,讓人想撞死,還不如 eshell 來的機靈……等等, eshell 不就是天生跨平台的 shell 么?

廢話不多說,這回先上圖 

eshell 夠壞的,shell 裡面能用 outline,我還真不知道有別的 shell 或者 editor 能夠做到……淘氣!

當然,僅僅一個 outline mode 還不能稱得上 evil ,eshell 裡面可以同時使用 shell 和 elisp 兩種語言。

  cmd $(elisp)  $(shell-command-to-string "cmd")

$ 不是必須的,甚至最外層的括弧也可以省略,不過據說可能會出問題

 

eshell 還有變態的修飾器和文件類型斷言

  echo *(:U) => ("BAR" "BIN/" "DEV/" "ETC/" "FOO" "HOME/" "LIB/" "TMP/" "USR/" "VAR/")

(:U) 括弧中以冒號開頭的是修飾器,U 表示轉換為大寫。

 

  echo *(^/) => ("bar" "foo")

(^/) 就是文件類型斷言了,/ 表示文件夾,前面的 ^ 表示 非

  echo ("foo" "bar" "baz" "foo")(:gs/foo/blarg/)  => ("blarg" "bar" "baz" "blarg")

是不是有點眼熟?請自由聯想……需要注意的是,修飾器和文件類型斷言要緊跟在列表的后 面。你沒有看錯,前面例子中的 * 不是列表,從哪個角度看都不是,但它爸是 eshell,所以它叫通配符

如果想了解更多修飾器和文件類型斷言的信息,M-x eshell-modifier(predicate)-alist 不過符號是用數字錶示的,理解起來有一定難度,點那個 customize 的鏈接。

下面又到了每月一次的配置文件時間

首先綁定一個快速啟動 eshell 的快捷鍵,我綁定的是 C-x C-x 。如果想多開,加個前綴 參數就可以了,比如 C-u C-x C-x 。

  (add-hook 'eshell-mode-hook (lambda()             (outline-minor-mode 1)             (color-theme-my-eshell)             (setq outline-regexp "^[^#$\n]* [#>]+ "                   scroll-margin 0                   eshell-scroll-to-bottom-on-output t                   eshell-scroll-show-maximum-output t)             (add-to-list 'eshell-output-filter-functions                           'eshell-postoutput-scroll-to-bottom)             (def-key-s eshell-mode-map                "<up>"     'eshell-previous-matching-input-from-input               "<down>"   'eshell-next-matching-input-from-input               "<tab>"    'user-tab               "<return>" 'user-ret)  ))  

儘管 eshell 也有 auto cd 的功能,就是輸入目錄回車,自動cd;不過我還是習慣空行按 tab 補全 cd ,那樣比較一致。

  (defun user-tab ()    (interactive)    (let ((input (eshell-get-old-input)))      (if (string-equal input "")          (insert-string "cd ")        (progn          (cond           ((string-equal input "cd  ")            (insert-string "_"))           ((string-equal input "cd --")            (delete-backward-char 2)            (insert-string "+"))           ((string-equal input "cd +-")            (delete-backward-char 2)            (insert-string "-"))           (t            (pcomplete))           )))))  

 

狠了狠心,我又加了一個 user-ret 。男人嘛,就應該對 Shell 狠一點

  (defun user-ret ()    (interactive)    (let ((input (eshell-get-old-input)))      (if (string-equal input "")          (progn            (insert-string "ls")            (eshell-send-input))          (eshell-send-input)          )))  

這個函數的作用是,空行按回車自動 ls,狠不狠?

 

下面是一些基本設置,不解釋

 

(setq eshell-save-history-on-exit t eshell-history-size 512 eshell-hist-ignoredups t eshell-cmpl-ignore-case t eshell-cp-interactive-query t eshell-ln-interactive-query t eshell-mv-interactive-query t eshell-rm-interactive-query t eshell-mv-overwrite-files nil ;; aliases-file 裡面不能有多餘的空行,否則會報正則表達式錯誤 eshell-aliases-file (expand-file-name "_eshell/eshell-alias" init-dir)

        eshell-highlight-prompt   t        ;; 提示符設置,下面兩項必須對應起來,        ;; 否則會報 read-only,並且不能補全什麼的        eshell-prompt-regexp      "^[^#$\n]* [#>]+ "        eshell-prompt-function    (lambda nil                                    (concat                                     (abbreviate-file-name                                      (eshell/pwd))                                     (if                                         (=                                          (user-uid)                                          0)                                         " # " " >>> ")))  )  

 

作為一個有時間觀念的人,我需要知道每一個命令花了多少時間。。。其實我總覺得 eshell 有點慢,這樣心裡感覺踏實一點 -__-!!!

  (add-hook 'eshell-load-hook            (lambda()(setq last-command-start-time (time-to-seconds))))  (add-hook 'eshell-pre-command-hook            (lambda()(setq last-command-start-time (time-to-seconds))))  (add-hook 'eshell-before-prompt-hook            (lambda()                (message "spend %g seconds"                         (- (time-to-seconds) last-command-start-time))))  

 

設置一些常用的命令

  (defalias 'ff 'find-file)  (defalias 'ee (lambda()(find-file (expand-file-name "44eshell.el" init-dir)))) (defalias 'aa (lambda()(find-file eshell-aliases-file))) (defalias 'rr (lambda()(find-file (expand-file-name "qref.org" sand-box))))  (defalias 'ss  'shell-command-to-string)  

 

差點忘了,auto-complete 設置

  ;; 自動開啟 ac-mode  ;; 需要 (global-auto-complete-mode 1)  (add-to-list 'ac-modes 'eshell-mode)  (setq ac-sources '(;; ac-source-semantic                     ;; ac-source-yasnippet                     ac-source-files-in-current-dir                     ac-source-filename                     ac-source-abbrev                     ac-source-words-in-buffer                     ;; ac-source-words-in-all-buffer                     ac-source-symbols                     ac-source-imenu))  

 

還有胡亂收集的一些小函數

  (defun eshell/ii (file)(ido-find-file file))  (defun eshell/ed (file1 file2)(ediff-files file1 file2))

 

;; 按一次 C-a 到命令在前面,再按一次到命令提示符的前面,感覺用處不大 (defun eshell-maybe-bol () (interactive) (let ((p (point))) (eshell-bol) (if (= p (point)) (beginning-of-line))))

(defun eshell/gvim (&rest args) "Invoke find-file' on the file. \"vi +42 foo\" also goes to line 42 in the buffer." (while args (if (string-match "\\\+\([0-9]+\)\'" (car args)) (let* ((line (string-to-number (match-string 1 (pop args)))) (file (pop args))) (find-file file) (goto-line line)) (find-file (pop args)))))



[火星人 ] 邪惡的 eshell已經有674次圍觀

http://coctec.com/docs/linux/show-post-65367.html