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
- Host: GitHub
- URL: https://github.com/nicholasbhubbard/mycd
- Owner: NicholasBHubbard
- License: mit
- Created: 2022-07-24T14:32:52.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-13T20:52:50.000Z (over 2 years ago)
- Last Synced: 2025-10-26T02:24:40.095Z (8 months ago)
- Topics: bash, shell
- Language: Shell
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
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