bcoughlan
bcoughlan

Reputation: 26627

Hooking bash commands?

I'm tired of doing long cd commands to other directories, so I want to make a little tool for jumping to the most recent folders.

I've searched and haven't found any sort of API that would let me trigger a process when a cd command is run. Can somebody point me in the right direction?

Working off the bash_history seems inefficient, and isn't always enabled.

Upvotes: 2

Views: 230

Answers (3)

amitkr
amitkr

Reputation: 1

If you're using a fairly recent version of bash you can just Ctrl+R and type a few letters to get the history. So, if you press Ctrl+R and type cd you'll get your last cd command. Press Ctrl+R again and you're get second last cd command and so on.

And yes, cd - takes you to your last working directory. You can also find your last working directory in shell variable $OLDPWD

Upvotes: 0

Dennis Williamson
Dennis Williamson

Reputation: 359965

Take a look at pushd and popd.

Upvotes: 2

inigomedina
inigomedina

Reputation: 1831

There is a classic bash script that makes easier directory navigation: http://linuxgazette.net/109/marinov.html

Upvotes: 2

Related Questions