Powered By

Powered by Blogger

Senin, 17 Mei 2010

Use Smart (Frecency) Directory Completition In Linux With Z

Z is a simple bash script which attempts to make the "cd" command smart, by creating a database of the most used as well as recently used directories (think of it as a simplified Zeitgeist written in BASH, for the "cd" command only) - it basically combines frequency and recency ("frecency") so you can get to the desired folder a lot faster.


To use Z, simply copy/paste the script code from HERE into a file, save the file to whatever location you want and then make it executable. I've saved the script in a folder called .scripts (hidden) in my home folder so you can do the same if you want.

Assuming you named the file z.sh and place it into the ~/.scripts folder, make it executable using the following commands:
cd ~/.scripts
chmod +x z.sh


Then you must add a line to your .bashrc file which you can edit using the following command:
gedit ~/.bashrc


and add this line at the bottom of the file, then save it:
. /exact/path/to/z.sh


Obviously, replace "/exact/path/to" with the exact path to where you saved the z.sh file. Note: there's a space between "." and the path to z.sh!

Then reload bash using the following command:
source ~/.bashrc


Once you're done setting everything up, "cd" into several folders to build up the database.


Then use Z like so (instead of "cd"):
z foo     # goes to most frecent dir matching foo
z foo bar # goes to most frecent dir matching foo and bar
z -r foo # goes to highest ranked dir matching foo
z -t foo # goes to most recently accessed dir matching foo
z -l foo # list all dirs matching foo (by frecency)

Tidak ada komentar:

Posting Komentar