leah blogs

July 2013

06jul2013 · Summer of Scripts: keep

Of course, for serious development I use Git, but sometimes I just hack around on a script, prepare a draft, or golf down some code and want to keep old versions of a file. For this, I use keep:

% keep foo
‘/home/chris/mess/2013/27/foo’ -> ‘/home/chris/mess/2013/27/foo.1’
% vi foo
% keep foo
‘/home/chris/mess/2013/27/foo’ -> ‘/home/chris/mess/2013/27/foo.2’
% keep foo
/home/chris/mess/2013/27/foo.2 not modified

As you can see, it creates numbered backup files—if the file has changed. The major benefit over doing this manually (with cp foo foo.1) is that it won’t ever overwrite an old revision accidentally because you blindly used your shell history.

I have not yet felt the need to add diffs or restoring of old versions.

(Tom Duff has an interesting, but more complicated version of this program.)

NP: Lia Ices—After Is Always Before

Copyright © 2004–2018