4 ms·
Running Shells in Emacs: An Overview
- e40 16y agoBased on comint, M-x su: (defvar explicit-su-file-name "/bin/su") (defvar explicit-su-args '("-")) (defun su (&optional buffer) (interactive (list (and current-prefix-arg (prog1 (read-buffer "SU buffer: " (generate-new-buffer-name "*su*")) (if (file-remote-p default-directory) ;; It must be possible to declare a local default-directory. (setq default-directory (expand-file-name (read-file-name "Default directory: " default-directory default-directory t nil 'file-directory-p)))))))) (setq buffer (get-buffer-create (or buffer "*su*"))) ;; Pop to buffer, so that the buffer's window will be correctly set ;; when we call comint (so that comint sets the COLUMNS env var properly). (pop-to-buffer buffer) (unless (comint-check-proc buffer) (let* ((prog explicit-su-file-name) (name (file-name-nondirectory prog)) (startfile (concat "~/.emacs_" name)) (xargs-name (intern-soft (concat "explicit-" name "-args")))) (apply 'make-comint-in-buffer "su" buffer prog (if (file-exists-p startfile) startfile) (if (and xargs-name (boundp xargs-name)) (symbol-value xargs-name) '("-i"))) (shell-mode))) buffer)
- jrockway 16y ago;; It must be possible to declare a local default-directory. make-local-variable is an interactive built-in function in `C source code'. (make-local-variable VARIABLE) Make VARIABLE have a separate value in the current buffer. Other buffers will continue to share a common default value. (The buffer-local value of VARIABLE starts out as the same value VARIABLE previously had. If VARIABLE was void, it remains void.) Return VARIABLE.
- jedbrown 16y agoDoes anyone here use M-x term? Is it stable? I've been put off by M-x shell because it only offers "line" interaction, so bash tab completion doesn't work. M-x term looks much better, but "ls /usr/bin" stalls the output part way through with my cursor off in the middle of the screen until I type a character in char mode, and I see stuff like error in process filter: cd-absolute: /hom/: no such directory error in process filter: /hom/: no such directory in messages. Is this sort of thing endemic?
- KC8ZKF 16y agoBash tab completion works for me in shell. GNU Emacs 23.2.1, x86_64-apple-darwin, on OS X 10.6.4. Term works fine as well.
- jedbrown 16y agoM-x shell, then type git <TAB> Is it completing subcommands, or is it trying to complete file names (I always observe the latter)? Now type alias foo='cd /' foo ls <TAB> See how it tries to complete paths in ~ (or wherever your last path was instead of in the new directory). GNU Emacs 24.0.50.1 (Linux), and every version of Emacs I've used in the last 10 years.
- KC8ZKF 16y agogit <TAB> completes filenames, but so does bash in terminal. I don't have any fancy bash completion dingleberries installed. (And yes, my beard is grey too.) The alias completion does appear broken, as you demonstrated.
- d0mine 16y agogit <TAB> completes subcommands ls <TAB> with the alias shows files from the root / GNU Emacs 23.1.1 (Linux)
- jedbrown 16y agoAre you using shell-mode or something else (e.g. term-mode)? Completion works fine in term-mode (in term-char-mode) because it actually uses bash's completion mechanism. In contrast, shell-mode only does line-based interaction with the shell, and it generates its own completions. It recognizes commands like cd, pushd, and popd to maintain its own mirror of the current path. As far as I know, there is no shell-mode implementation that actually calls the shell for completions.
- chrismealy 16y agoHow did I not know about M-x ansi-term all these years? Argh! (Thanks for the link)
- revorad 16y agowow it's fast!
- jedbrown 16y agoWell, sort of. urxvt: $ time ls /usr/bin 0.036 real 0.013 user 0.020 sys 93.76 cpu emacs ansi-term: 4.265 real 0.023 user 0.023 sys 1.09 cpu
- leif 16y agoNot much beats urxvt, but even gnome-terminal beats ansi-term. urxvt: real 0m0.314s user 0m0.080s sys 0m0.040s gnome-terminal: real 0m1.228s user 0m0.090s sys 0m0.040s ansi-term: real 0m6.493s user 0m0.150s sys 0m0.030s Also, ls --color=auto really messes up ansi-term. It glitches all over the place and I think treats some color codes as carriage returns or other motion commands for some reason.
- ivanstojic 16y ago+1 definitely! Thank you for a great and refreshing info on shells! I've been using eterm only since I started using Emacs about three years ago, and didn't even know about ansi-term and friends.
- jfb 16y agoI know I should be using eshell, particularly now that daemon mode is "stable" on OS X, but there is a lot of unlearning involved when grep pops up a result buffer. Why, yes, as a matter of fact, my beard is grey.
- technomancy 16y agoLittle-known fact about Eshell: not only can you implement your prompt functions and highlighting in lisp, you can also (a) pipe output directly to buffers and (b) invoke M-x commands from the shell: a) $ ifconfig > #<buffer interfaces> b) find-file README.txt # same as doing C-x C-f
- jfb 16y agoAwesome. There are many fact that remain little known in eshell, it seems.
- philjackson 16y agoAnd if e-shell isn't your thing, may I humbly suggest this: http://www.shellarchive.co.uk/content/emacs_tips.html#have-emacsclient-accept-stuff-from-stdin http://www.shellarchive.co.uk/content/emacs_tips.html#have-e... I alias that script to 'e' so I can do this: $ ifconfig | e $ e README.txt
- rayvega 16y agoIf you are on Windows, another alternative is running PowerShell as an interactive shell within Emacs: http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/10/run-powershell-as-a-shell-within-emacs.aspx http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/10/run...