This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Desktop Software

Retain and recall long paths with rr utility

By Joe Barr on October 16, 2007 (9:00:00 AM)

Share    Print    Comments   

rr -- short for retain and recall -- is a small utility that's both simple and useful. When you need to work on a config file buried deep in the bowels of your system and don't want to type its full path name to do so, rr is just the thing.

To install rr, download the source and decompressed it with a command like tar xzf rr-1.3.tar.gz. Enter the resulting rr-1.3 subdirectory and run make and then sudo make install. The installation includes a man file, so if you need a handy cheat cheat for rr, ask the man.

Now let's see how to use it. Suppose that every now and then you need to edit the config file for your RDBMS, which lives at /usr/local/rdbms/etc/my.config. To simplify that task, use rr to remember the full path name and then to recall it when you need to edit the file.

Use the command rr /usr/local/share/rdbms/etc/my.config to retain the full file path. If you try to tell rr to remember a file that's not there, you'll be told, "rr: failed to retain: /usr/local/share/rdbms/etc/my.config (non-existent or non-accessible file)."

The next time you need access to the file, preface the command to open the file in your editor with rr, and specify only the file name:

rr gedit my.config

As long as the file name you want to edit is unique, that works well. But what happens if your HTTP server also has a my.config file, and you need to work with it as well?

When you tell rr to remember the second my.config file path, it will happily do so, but it will also forget all about the first one. So the next time you want to edit your database server config, and use rr to recall it for you, you'll get the HTTP config file instead. If you're unsure of which my.config file rr has stored, enter rr my.config and it will print the full file path for you.

You can also use rr to store long path names to a directory. In this case, start as before, by telling rr to remember the directory path using the following command:

rr /usr/local/share/rdbms

The next time you need to work in that directory, simply enter:

cd `rr rdbms`

Note the use of the accent grave -- a.k.a. backtick -- marks around the rr command in this usage instead of the regular single or double quotation mark. Only the mark on the key beneath the tilde on the top row of keys (at least on US QWERTY keyboards) will expand properly.

rr is a sweet, simple, and useful tool. If its inability to recall two file paths ending in the same file name is a problem for you, consider using symbolic links, which you can name anything you like in order to avoid name collisions, and then use rr with them instead of the actual file names. Or, since the program is free software, you can modify the program itself to make it behave as you desire.

Share    Print    Comments   

Comments

on Retain and recall long paths with rr utility

Note: Comments are owned by the poster. We are not responsible for their content.

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 83.100.197.200] on October 16, 2007 12:50 PM
A useful little utility and similar to comment - see http://server50049.uk2net.com/comment - which takes notes and recalls commands depending on your location in the filesystem.

#

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 82.128.194.90] on October 16, 2007 04:02 PM
ctrl-r in bash does this and much more :)

#

not Ctrl-r

Posted by: Michael Shigorin on October 17, 2007 03:48 PM
Nope, one has to keep some quite precise stack inside one's head to use bash history search effectively. But those tend to use zsh anyways. :)

#

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 82.95.236.142] on October 16, 2007 08:20 PM
Here's a somewhat related shell function you could put in

~/.bashrc or ~/.bash_profile:





cdof()

{

# cd to the directory of a file



if [ -d $1 ]

then

builtin echo "$1: Is a directory"

return 1

else

# cd `dirname $1`

builtin cd ${1%${1##*/}}

fi

}







Bauke Jan Douma


#

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 90.202.61.244] on October 16, 2007 10:20 PM
and don't forget `export rdbms=/usr/local/share/rdbms; cd $rdbms`

#

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 172.20.0.102] on October 17, 2007 09:15 AM
Or, since you allready talk about symbolic links, just make a directory "favorites" in your $HOME and put symbolic links to often used files on your disc there. That way you don't need a new utility that actualy just replaces the well-known concept of symbolic links with some hidden config file ....

#

Retain and recall long paths with rr utility - bug

Posted by: Dave P on October 17, 2007 06:11 PM
From the man page,
recall with

$rr emacs //shortForm

Your examples omit the //
which gives the impression it doesn't work?


Please amend it?

#

Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 63.81.1.27] on October 19, 2007 09:45 PM
actually why dont you use bash yanking? it has a built in ring to memorize paths, or whatever else commands you don't feel like typing out over and over.
ctrl-w will delete the word previous to the cursor
ctrl-y pastes the last word in your yank-ring
alt-m will rotate the word it pastes until you hit the word you're looking for.

simple.

#

Re: Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 68.60.7.104] on October 20, 2007 06:50 AM
That seems to be more time consuming and less specific, and annoying to use in the long term. I'd use this or Ctrl-R as mentioned above over that.

#

Re(1): Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 63.81.1.27] on October 22, 2007 07:28 PM
ctrl-r doesnt 'retain' single words like bash yank ring capable of doing (unless the command is actually 1 word). So regardless if what you think is more specific, the yank ring is specifically for tasks like what this tool is trying to do.

#

Re(2): Retain and recall long paths with rr utility

Posted by: Anonymous [ip: 63.81.1.27] on October 22, 2007 11:04 PM
furthermore the yank ring is cmdline, not just restricted to bash, it will work in gdb, etc

#

People who don't use Emacs are doomed to reimplement parts of it, poorly.

Posted by: Anonymous [ip: 193.110.109.30] on October 26, 2007 10:40 PM
Sorry, couldn't resist.

#

free movies

Posted by: Jen on October 31, 2007 02:04 AM
I found http://www.boxsweeper.com has a lot of movies anime music and games!This website is quite great! And it's free for you to streaming and download! Check it out and enjoy it! It will save you much time and money! Don't forgot to thanks me........ha ha

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya