Emacs package for quickly navigating to a specific parent directory in
eshell
without having to repeatedly typing cd ..
.
Navigating to a specific parent directory is achieved using the
eshell-up
function, which can be bound to an eshell
alias such as
up
.
To demonstrate how to use eshell-up
let’s assume that the current
working directory of eshell
is:
/home/user/first/second/third/fourth/fifth $
Now, in order to quicky go to (say) the directory named first
one
simply executes:
/home/user/first/second/third/fourth/fifth $ up fi
/home/user/first $
This command searches the current path from right to left (while
skipping the current directory, fifth
) for a directory that matches
the user’s input (fi
in this case). If a match is found then
eshell
changes to that directory, otherwise it does nothing. If, on
the other hand, no argument is passed to eshell-up
, this command
simply changes to the nearest parent directory (like cd ..
does).
It is also possible to compute the matching parent directory without
changing to it. This is achieved using the eshell-up-peek
function,
which can be bound to an alias such as pk
. When this function is
used in combination with subshells the matching parent directory can
be passed as an argument to other functions. Returning to the
previous example one can (for example) list the contents of first
by
executing:
/home/user/first/second/third/fourth/fifth $ ls {pk fi}
<directory contents>
...
eshell-up
is available via MELPA. To add it to Emacs execute the
following:
package-install RET eshell-up RET
Now, put the following in your .emacs
file:
(require 'eshell-up)
It is recommended to invoke eshell-up
and eshell-up-peek
using
aliases as done in the examples above. To do that, add the following
to your .eshell.aliases
file:
alias up eshell-up $1 alias pk eshell-up-peek $1
To make eshell-up
searches case sensitive:
(setq eshell-up-ignore-case nil)
To print the matching parent directory before changing to it:
(setq eshell-up-print-parent-dir t)
The test are written using ERT, and can be executed as follows:
load-file eshell-up-tests.el
ert t
Alternatively, the tests can be run in batch mode:
emacs -Q --batch -L . -l ert -l eshell-up-tests.el -f ert-run-tests-batch-and-exit
This package is inspired by bd, which uses bash to implement similar functionality.