reddit / emacs

Mastering Eshell, Emacs's Elisp Shell

mickeyp · 2022-08-15 14:47
mysockinabox · 2022-08-15 18:02
I respect anybody that really uses eshell primarily. I just could never do it. vterm is so good now that using the same tool set I use outside emacs is too pleasant to switch.
MitchellMarquez42 · 2022-08-15 18:33
I'm gonna have to read this three times. This week I'll switch to eshell, I swear. Really. I'll get rid of vterm, even. I'll remove the default terminal.
noman_032018 · 2022-08-15 20:22
I would but I simply cannot exclusively because there are some things for which it doesn't work best, sadly: - using [tmux](https://en.wikipedia.org/wiki/Tmux) over it to manage remote processes reliably... I haven't yet bothered to read & setup [dtache](https://gitlab.com/niklaseklund/dtache) which would solve that problem (kudos to the maker). - [ncurses](https://invisible-island.net/ncurses/announce.html) programs just won't work on eshell, you require terminal emulation for those.
colemaker360 · 2022-08-15 21:43
If I were moving from bash, I’d absolutely give it a shot. But as a fish user, I’ve had a tough time finding enough compelling about eshell to make it stick when I’ve tried it in the past.
7890yuiop · 2022-08-15 22:21
> ncurses programs just won't work on eshell, you require terminal emulation for those. Nothwithstanding that I don't use eshell either, do note that it has a notion of "visual" commands requiring a proper terminal, which it will automatically run in a term buffer. It knows several by default, and you can tell it about anything else.
noman_032018 · 2022-08-15 22:30
I did not know of that feature. Neat.
7890yuiop · 2022-08-15 22:55
For more information, I notice that Mickey's article (unsurprisingly) discusses this feature: https://www.masteringemacs.org/article/complete-guide-mastering-eshell#visual-commands The config is more fine-grained than you might imagine -- not only can you tell it to use a terminal for an entire command (e.g. `top`), but also that only *particular invocations* of a command (sub-commands and/or specific options) should use a terminal (e.g. `git log`; or any `git` command using the `--paginate` option). That's very nice!
noman_032018 · 2022-08-15 22:58
I had given it a very cursory glance, but much like that other commenter, I consider it worth a few thorough reads just in case.
frozeninfate · 2022-08-16 00:03
Theres a package to make the visual commands use vterm instead of term as well
frozeninfate · 2022-08-16 00:05
I couldn't switch off eshell as its too convenient to just be able to use cd/cp/etc across users/machines. `cd /sudo::/etc` or `cp file /ssh:device:` is great
xenodium · 2022-08-16 04:37
Mentioned on [tweet](https://twitter.com/xenodium/status/1559258240998932481?s=21&t=CxIY2qtBC13xOn2hO2-MmQ) but [eshell can do images also](https://xenodium.com/wizard-zines-comics-eshell-util/) and [imenu](https://xenodium.com/imenu-on-emacs-eshell/) :)
emax-gomax · 2022-08-16 07:18
cd you can do with find-file, copy you can do with scp or rsync and probably the same syntax except /ssh:. Personally I'm aware of this feature but I've never really used it.
frozeninfate · 2022-08-16 07:21
Yes, there are other tools that do the same thing. But I dont have to remember if its scp or rsync or what their flags are; the important thing is that I can do all these things *with the same familiar interface*. Also find-file doesn't replace cd as the result is not a root shell which I can run commands in, and as part of current shell
dakra · 2022-08-16 08:23
I have this eshell command in [my config](https://github.com/dakra/dmacs/blob/25a934449589aa165bd7fa4dd325d24887a522d9/init.org#L3855-L3866) that's basically like `cat` but with syntax highlighting: (defun eshell/ccat (file) "Like `cat' but output with Emacs syntax highlighting." (with-temp-buffer (insert-file-contents file) (let ((buffer-file-name file)) (delay-mode-hooks (set-auto-mode) (if (fboundp 'font-lock-ensure) (font-lock-ensure) (with-no-warnings (font-lock-fontify-buffer))))) (buffer-string)))
emacs_expert · 2022-08-16 11:41
I actually like eshell, but it had this annoying habit of always clobbering my shell history. I finally decided to look into it, and found this snippet that made it much more usable for me: https://emacs.stackexchange.com/a/18569/15023 This is my config: ;; Fix eshell overwriting history. ;; From https://emacs.stackexchange.com/a/18569/15023. (setq eshell-save-history-on-exit nil) (defun eshell-append-history () "Call `eshell-write-history' with the `append' parameter set to `t'." (when eshell-history-ring (let ((newest-cmd-ring (make-ring 1))) (ring-insert newest-cmd-ring (car (ring-elements eshell-history-ring))) (let ((eshell-history-ring newest-cmd-ring)) (eshell-write-history eshell-history-file-name t))))) (add-hook 'eshell-pre-command-hook #'eshell-append-history) (add-hook 'eshell-mode-hook #'(lambda () (setq eshell-exit-hook nil))) (use-package em-hist :ensure nil :config (setq eshell-hist-ignoredups t ;; Set the history file. eshell-history-file-name "~/.bash_history" ;; If nil, use HISTSIZE as the history size. eshell-history-size 10000 ) )
deaddyfreddy · 2022-08-16 17:31
>I haven't yet bothered to read & setup dtache which would solve that problem (kudos to the maker). it's [https://git.sr.ht/\~niklaseklund/detached.el](https://git.sr.ht/~niklaseklund/detached.el) now (btw, it just works) > ncurses I think Emacs UI is superior to ncurses, but even if you need to use something like that - `eshell-visual-subcommands` (it's mentioned in the OPs link, btw).
deaddyfreddy · 2022-08-16 17:35
how is it better than `find-file-readonly`?
dakra · 2022-08-16 19:19
Different use-case. Sometimes I just want to peak in a script/makefile/log and have the output inside the eshell session just like the `cat` command. So with the snippet above I can simply do `ccat Makefile` and have the Makefile content with syntax highlighting right above my prompt. While `find-file` etc also works but that opens the file in a new buffer which I then first have to move to a different window to see both and/or close again.
noman_032018 · 2022-08-16 19:32
> it's https://git.sr.ht/~niklaseklund/detached.el now (btw, it just works) Noted, I hadn't noticed the switch, bookmarks have now been updated. > I think Emacs UI is superior to ncurses I mostly agree, other than some awkwardness around the ability to `sudo $command` ncurses-based programs vs not being able to nicely with Emacs (hacking around with a sudo'd pipe process interacting with a system daemon is feasible but it gets more awkward when administrating remote hosts -- dtache might help with that), it's unambiguously superior and integrates better. Unfortunately few programs bother with making such interfaces. > if you need to use something like that - eshell-visual-subcommands (it's mentioned in the OPs link, btw). Yeah, others have mentioned it as well, highlighting that I need to re-read it with more attention.
deaddyfreddy · 2022-08-16 23:57
> sudo $command tramp?
deaddyfreddy · 2022-08-16 23:59
`M-x find-file-read-only-other-window`
noman_032018 · 2022-08-17 00:30
For eshell and other commands yeah that works but that's the usual unix shell-like fallback, not a first-class Emacs UI like [transmission.el](https://github.com/holomorph/transmission) (which doesn't require super-user (or other user-switching) shenanigans since its RPC supports authentication and can be reverse-forwarded with SSH, a luxury that many other RPC-less programs do not share). As far as implementing UIs using TRAMP as a transport for a backend program, I know you can launch remote programs with TRAMP (and in eshell although I'm not sure how exactly that happens), but I'm not sure how you'd programmatically interact with them.
_viz_ · 2022-08-17 00:44
Tramp is a transparent protocol. As long as you have the right default-directory, it should just work.
noman_032018 · 2022-08-17 00:48
Sadly it seems a bit more complicated, as something like the following fails to produce the expected output: (let ((default-directory "/sudo:root@localhost:/root")) (message "%s" default-directory) (call-process "whoami" nil t nil)) It does show the right directory, but call-process outputs my current user instead.
dakra · 2022-08-17 07:04
I'm not sure I understand what you mean. If I'm in an eshell session, of course I can just open any file in a buffer (and optionally also open that buffer in a new window or even frame) but sometimes I don't want that and I just want to `cat` the file. This command is like `cat` but adds colour to it.
kamui78 · 2022-08-17 13:29
Is there any way to make the completion and history on eshell work like the zsh one. I also noticed that the documentation is not complete. Does anybody know if Emacs 29 is going to improve eshell in any significant way? Right now I am using vterm and I would like to switch to eshell.
Illiamen · 2022-08-17 14:32
There has been plenty of work on Eshell, but whether it counts as significant is up to you: https://git.savannah.gnu.org/cgit/emacs.git/log/?qt=grep&q=eshell Some more noticeable changes might be: - New "electric forward slash" module - New predicate `G` - New piping (`*|`, `*<`, `*>`) to avoid Emacs buffers
kamui78 · 2022-08-17 14:36
Wow! Thanks a lot. Very interesting.
nu0or · 2022-08-21 10:03
very nice