Portable Emacs Eshell Aliases
I maintain one emacs config file (.emacs) for all environments and systems whereever I use emacs. From time to time I use eShell but aliases were differing from system to system. The reason was, that they were stored in a separate file (~/.emacs.d/eshell/aliases) which I do not re-distribute.
So, my solution was to maintain eshell aliases inside my .emacs file. Here are my current alias definitions:
;; actual aliases (+alias 'l '(ls -laF)) (+alias 'll '(ls -l)) (+alias 'la '(ls -a)) (+alias 'lt '(ls -ltr $*)) (+alias '.. '(cd ..)) (+alias '... '(cd ../..)) (+alias '.... '(cd ../../..)) (+alias '..... '(cd ../../../..)) (+alias 'md '(mkdir -p)) (+alias 'emacs '(find-file $1)) (+alias 'less '(find-file-read-only $1))
As you can see, I use a pretty handy function +alias to create them and I use symbols, not strings which looks cleaner. For this to work, I use the following function:
(setq eshell-command-aliases-list ())(defun +alias (al cmd) “handy wrapper function to convert alias symbols to alias
strings to avoid writing 4 quotes per alias. AL is a single-word
symbol naming the alias, CMD is a list symbol describing the
command." (add-to-list ’eshell-command-aliases-list (list (symbol-name al) (mapconcat ‘symbol-name cmd ” “))))
So, first the aliases list will be cleared, just in case there's some aliases file left in the filesystem (which I ignore from now on). The function +alias then converts the given symbols to strings and adds them to the alias list.
I could of course use strings directly but that's too much quotes to type and looks confusing. Just for completeness, here's how the aliases list looks like after the above conversion:
(("less" "find-file-read-only-other-window $1") ("emacs" "find-file-other-window $1") ("md" "mkdir -p") ("....." "cd ../../../..") ("...." "cd ../../..") ("..." "cd ../..") (".." "cd ..") ("lt" "ls -ltr $*") ("la" "ls -a") ("ll" "ls -l") ("l" "ls -laF"))