There are many shell interface within Emacs, shell, eshell, and ansi-term can call the shell you like. IMO eshell is the one intergrated with Emacs the most and I use most.
The most intergration that the others don’t have (to my knowledge) is that we can call lisp functions within the shell. like input
will give “Hello, world!” in the mini buffer.
The usage is pretty simple, just add
to your .emacs.
Eshell can save the input history, as many other shells can do. And by default it will ask if you want to save the history when exit (eshll or Emacs). Add this if you feel that’s annoying.
Note I’m using the CVS version of Emacs. Depending on your version, it might be
And this sets the history length
I use bash outside Emacs, so I want eshell to be like Bash as much as possible:
This emulates the bash history save.
By default eshell do the completion the Emacs way, i.e, cycle through
all the possible values. And Bash will complete as much as possible,
and then wait for the next charater. This makes eshell like Bash:
This makes it more like in a terminal:
(setq eshell-scroll-to-bottom-on-output t)
(setq eshell-scroll-show-maximum-output t)
(add-to-list ‘eshell-output-filter-functions ‘eshell-postoutput-scroll-to-bottom)
By default C-a will put the cursor to the begining of the line, cause eshell is an Emacs buffer too. This is not like bash. And I’ve found this in EmacsWiki :
;; from ZwaX at EmacsWiki
;; I use the following code. It makes C-a go to the beginning of the
;; command line, unless it is already there, in which case it goes to the
;; beginning of the line. So if you are at the end of the command line
;; and want to go to the real beginning of line, hit C-a twice:
(defun eshell-maybe-bol ()
(interactive)
(let ((p (point)))
(eshell-bol)
(if (= p (point))
(beginning-of-line))))
(add-hook ‘eshell-mode-hook
‘(lambda () (define-key eshell-mode-map "\C-a" ‘eshell-maybe-bol)))
We can type “man bash” to view the bash man page in man-mode. We want “info bash” work too:
;; will work.
(defun eshell/info (subject)
"Read the Info manual on SUBJECT."
(let ((buf (current-buffer)))
(Info-directory)
(let ((node-exists (ignore-errors (Info-menu subject))))
(if node-exists
0
;; We want to switch back to *eshell* if the requested
;; Info manual doesn’t exist.
(switch-to-buffer buf)
(eshell-print (format "There is no Info manual on %s.\n"
subject))
1))))
However, there’s something eshell is not good at: ansi color and controls. We can use ansi-term for these:
(add-hook
‘eshell-first-time-mode-hook
(lambda ()
(setq
eshell-visual-commands
(append
‘("mutt" "vim" "screen" "lftp" "ipython" "telnet" "ssh")
eshell-visual-commands))))
shell-toggle.el makes us jump to the shell buffer with or without a “cd” command. And it can call eshell too:
;; http://www-verimag.imag.fr/~moy/emacs/shell-toggle-patched.el
(autoload ’shell-toggle "shell-toggle"
"Toggles between the shell buffer and whatever buffer you are editing."
t)
(autoload ’shell-toggle-cd "shell-toggle"
"Pops up a shell-buffer and insert a \"cd <file-dir>\" command." t)
;; use eshell by default
(setq shell-toggle-launch-shell ’shell-toggle-eshell)
;; C-c g s
(define-key goto-global-map "S" ’shell-toggle-cd)
(define-key goto-global-map "s" ’shell-toggle)
Post a Comment
You could use <code type="name"> to get your code colorized