Brian's Waste of Time

Wed, 30 Nov 2005

Some (Possibly) Useful Tools

I saw Bruce's post about (the incredibly useful) pbcopy/pbpaste today. They rock! That said, they are not quite what I need a lot of times, so here are a couple quick tools I whipped together for ye shell bangers.

get and put : These are basically a clipboard for the shell. Get takes input from standard in and stashes it. It is like yank or copy in a gui. Put does the opposite, it takes whatever get stashed and spews it to standard out (paste). No biggie, but useful: (I inserted the blank lines in the output, for readability)

brianm@kite:~/src/activemq$ cat build.properties | get

brianm@kite:~/src/activemq$ cd ../wombatattack

brianm@kite:~/src/wombatattack$ put > activemq.properties

brianm@kite:~/src/activemq$ cd ../wombatdefense

brianm@kite:~/src/wombatdefense$ put > activemq.properties

Now, the more fun tools are push and pop which are like put and get except they operate on a stack =)

brianm@kite:~/src/jdbi$ for x in $(find . -name Test*.java); do echo $x | push; done 

brianm@kite:~/src/jdbi$ pop
./src/test/org/skife/jdbi/TestSQLOperations.java

brianm@kite:~/src/jdbi$ pop
./src/test/org/skife/jdbi/TestScriptStuff.java

brianm@kite:~/src/jdbi$ pop
./src/test/org/skife/jdbi/TestRowMap.java

brianm@kite:~/src/jdbi$ pop --clear

The shocking part is that, as far as I know, these type of tools aren't part of the standard shell environment!

writebacks...

Andrew


Maybe your use casse isn't adequate, how do you mean not part of standard shell? In the first example, wouldn't; cat build.properties > ../wombatdefense/activemq.properties do exactly the same thing? In the second, I think you mean to use a basic list and access it in reverse order? If that were the case I fail to see how your purposes couldn't be served better by just using a one line shell script, as opposed to a forty line program? Shell banger doesn't get it.

Brian McCallister

Use Cases
You ca (and I have many times) simply cat'ed to a temp file, which you'll note is what this script does. get/put are no big deal... except they are a pretty common case, so I am surprised they don't exist in the (even slightly) simpler form. For the second, the key thing is that you can push whatever you want (whole files is actually the use case I needed it for when I whipped the initial version together) and they'll remain there until you ipe your temp directory. If you can do a persistent stack or list in a bash one liner I'll be impressed, I don't know how. Ah well, if you don't need em, don't use em =) I use em.

Craig Hockenberry

Bad link
The link for the "put" source code points to the "get" source code. I worked around the problem by manually replacing "get" with "put" in the URL.

Andrew


Hi Brian, There are numerous strategies for simple, one-line stacks. For data: data="this that and the other" for files: cat file1 file2 filen > fifo & Then, when you need the data, cat fifo... Of course, it's more useful when whatever it is works... Andrew

comment...

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Spam Guard, translate l33t to English: (hint, it's an Australian animal, plural form)
Comments:
Save my Name and URL/Email for next time