Eshell tips
Today I am some providing eshell tips!
What is eshell
Eshell is a shell-like command interpreter implemented in Emacs Lisp
John Wiegley is the original author of Eshell.
Resources
https://www.masteringemacs.org/article/complete-guide-mastering-eshell
Also, read the New Manual (1 July 2023)
Jim Porter
https://www.gnu.org/software/emacs/manual/html_mono/eshell.html
Useful section on Bugs and ideas
Use Plan9 Smart Display
Provides a Plan9 like style interface. It automatically paginates command outputs, making it easier to read them, particularly when dealing with large amounts of data. In a normal shell, output trails the command. With the Plan9 Smart Display it precedes it and one need not scroll backwards to find data. This means you never need to pipe commands with | more
or | less
.
;; Plan 9 Smart Shell (require 'em-smart) (setq eshell-where-to-jump 'begin) (setq eshell-review-quick-commands nil) (setq eshell-smart-space-goes-to-end t) ;; If the above does not work, try uncommenting this. (add-to-list 'eshell-modules-list 'eshell-smart)
Creating aliases
Some useful commands:
find-file + name of file dired . find-name-dired . \*fam\*
These become even more useful when turned into aliases
alias name definition
Note: You must enclose the alias definition in single quotes.
You can use conventions like $1 for the first argument, $2 for the second, and so on. Typically one uses $* for all arguments.
Sme Alias examples:
alias f 'find-file $1' alias d 'dired $1' alias fd 'find-dired $PWD ""' ;; Gives recursive listing of all files and directories in your current directory alias de cd ~/.emacs.d && ls alias fnd 'find-name-dired $1'
Directly edit the "alias" file located in dot emacs dot d
Eshell writes out the alias definitions to the eshell-aliases-file
, usu. in .emacs.d/
;; Update alias file after editing, no restart required (global-set-key (kbd "C-c u") 'eshell-read-aliases-list)
Force eshell to invoke external command by prefixing the name of command with asterisk
e.g. ls versus *ls
e.g which ls versus which *ls
Normally it is not necessary to invoke external commands.
cd used without arguments take you to the Home directory
Make it automatic that when you change directories, you get an ls
listing
;; Do automatic ls after `cd' (setq eshell-list-files-after-cd t)
Set your default ls
listing switches
;; ls default switches (setq eshell-ls-initial-args '("-alth"))
Redirect the output of any command to an Emacs Buffer
This is the syntax:
grep "eshell" init.org >> #<buffer *wiegley*>
Use the keybinding C-c M-b
to insert the printed buffer name at point
One can also create a new buffer by assigning a new name
eshell toggle
https://github.com/4da/eshell-toggle
;; Additional package: Toggle eshell window (use-package esh-toggle :bind ("C-x C-z" . eshell-toggle))
Clear the screen
alias c clear-scrollback
See directory stack
cd =
cd -12
cd =Windows
Create a 911 contacts search
e.g. ambulance
;; Permanent aliases (add-hook 'eshell-mode-hook (lambda () (eshell/alias "911" "grep -ri $1 c:/tan/contacts.txt")))