Displaced Geek

Just a city geek and father coming to terms with being replanted in farm country

hist2bin v0.2

The other night I decided to throw together a script that would bring to life a little thought I first had over on reddit.

The thought was that for hard to remember commands you’ll use more than once, to automatically save them before wiping your command history.

Right now it’s sloppy but it:

  1. extracts the commands you want
  2. creates files containing those commands, one per file
  3. names them per your comment when you ran the command
  4. handles whitespace in the data and filename
  5. cleans up after itself
  6. reports the filenames on exit
  7. drastically reduces the chances of a duplicate-named file issue

The code is after the jump

 history -w ~/testfile
 awk /##/ ~/testfile > ~/testfile2
 d=`date +%N`
 while read line ; do
     file=$(echo $file | tr A-Z a-z | tr ' ' _)
     if [ ! -f $file ]
         echo $data > $file
         echo $data > $file
     echo File$N=$file
 done < ~/testfile2
 rm ~/testfile
 rm ~/testfile2
 history -c

Written by Peter

August 5, 2011 at 1431

Posted in geek

Tagged with , , , ,

4 Responses

Subscribe to comments with RSS.

  1. Ahhhhhh, the “geek” part of your blog name finally reveals itself. I see now.


    August 5, 2011 at 1452

    • Indeed.


      August 5, 2011 at 1626

    • All I see is blah blah blah blah


      August 8, 2011 at 2128

  2. Amazing! All that farming hasn’t slowed the old mind down a bit! Hah!


    August 5, 2011 at 1651

Comments are closed.

%d bloggers like this: