Skip to content

peterwvj/eshell-up

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eshell-up.el

https://melpa.org/packages/eshell-up-badge.svg https://stable.melpa.org/packages/eshell-up-badge.svg https://travis-ci.org/peterwvj/eshell-up.svg?branch=master http://img.shields.io/:license-gpl3-blue.svg?style=flat-square

Emacs package for quickly navigating to a specific parent directory in eshell without having to repeatedly typing cd ...

Usage

Navigating to a specific parent directory is achieved using the eshell-up function, which can be bound to an eshell alias such as up.

Examples

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>
...

Installation

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

Configuration (optional)

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)

Testing

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

Credits

This package is inspired by bd, which uses bash to implement similar functionality.