An open API service indexing awesome lists of open source software.

https://github.com/nicholasbhubbard/mycd

Directory history for Bash
https://github.com/nicholasbhubbard/mycd

bash shell

Last synced: about 2 months ago
JSON representation

Directory history for Bash

Awesome Lists containing this project

README

          

# -*- mode:org;mode:auto-fill;fill-column:80 -*-
#+author: Nicholas Hubbard

A bash function that wraps =cd= to log your directory history.

* Why Does This Exist?
It is extremely common to need to go back to a directory you've visited
recently. =mycd= exists to solve this problem in the simplest way possible by
remembering the last 15 (by default) directories you've visited and providing
a simple way to list and jump to these directories. The directory history is
saved across sessions, and each user gets their own history.

* Installation
#+BEGIN_SRC
git clone https://github.com/NicholasBHubbard/mycd
cp mycd/mycd.bash /etc/profile.d/
#+END_SRC

You can of course install =mycd.bash= to any directory you wish.

Next you will need to source =mycd.bash= from your =.bashrc=. It is also
recommended that you alias =cd= to =mycd=. Add the following lines to your
=.bashrc=.
#+BEGIN_SRC
if [ -r $DIR/mycd.bash ]; then
. $DIR/mycd.bash
alias cd=mycd
fi
#+END_SRC

* Usage
=mycd= works the same way as regular =cd= except it accepts two special
arguments.

The first special argument is =--= which lists your directory history.
#+BEGIN_SRC
[nick@slacktop ~]$ cd --
1 /home/nick
2 /etc/rc.d
3 /home/nick/Pictures
4 /
5 /etc
#+END_SRC
The second special argument is =-N= where =N= is one of the numbers listed in
the =--= output. This changes your directory to the =N='th directory in your
history.
#+BEGIN_SRC
[nick@slacktop ~]$ cd -3
[nick@slacktop Pictures]$
#+END_SRC

* Customization
The =MYCD_HIST_LENGTH= variable can be set to control the number of history
items that are remembered. This value defaults to 15.

* License
MIT