Pages

Wednesday, February 23, 2011

Feeling dumb

So as some of you know, I wrote a little script to make my life easier during the process of writing this novel. The purpose of this script was to facilitate multiple versions of my novel. I have a nasty tendency to rewrite parts of my story and I wanted to be able to keep track. This was the script:

#!/bin/bash
IFS="
"
function findfile {
for word in $filetype; do
    case $word in
        .tex) find /home/ray/ -name *.tex | sort;;
        .odt) find /home/ray/ -name *.odt | sort;;
        .doc) find /home/ray/ -name *.doc | sort;;
        .html) find /home/ray/ -name *.html | sort;;
    esac
done
}

function editfile {
for word in $filetype; do
    case $word in
        .tex) gedit $response;;
        .odt) oowriter $response;;
        .doc) oowriter $response;;
        .html) oowriter $response;;
    esac
done
}

function makerevisions {
if [ -d $directory/Revisions/ ];
then
    echo "Revisions directory exists"
    mkdir $directory/Revisions/$(date +%F-%R)
    cp $response $directory/Revisions/$(date +%F-%R)/
else
    echo "Revisions directory does not exist"
    mkdir $directory/Revisions/
    mkdir $directory/Revisions/$(date +%F-%R)
    cp $response $directory/Revisions/$(date +%F-%R)/
fi
}

filetype=$(zenity \
--list \
--title="Select filetype" \
--column="Filetype" \
    .tex \
    .odt \
    .doc \
    .html)   
if [ "$filetype" == "" ]; then
    exit 1
fi

response=$(zenity \
--list \
--title="Select file" \
--column="File" \
    $(findfile))
filename=${response##/*/}
directory=${response%/*.***}
if [ "$response" == "" ]; then
    exit 1
fi

editfile $*
makerevisions

echo $filetype
echo $response
echo $filename
echo $directory

unset IFS

Anyways, to continue my story, I found out that I was being extraordinarily dumb. In many ways I was simply trying to reinvent the wheel. I forgot that there were many tools out there that did the exact same thing. Basically, what I was trying to do was a primitive version control script. I realized relatively recently (to may shame) that I could use things like git and svn to do the exact same thing, except better. So I took a look at a few different tools and I finally decided upon using git. I chose git because, well simply, it appeared to be the easiest to learn and I could use it offline. Now I have a script that I worked so hard on (a symptom of my amateurish scripting abilities) that's, for all intents and purposes, useless.

As a side note, it should be mentioned that git these 'software revision control' tools work particularly well because I am using LaTeX. I am unsure as to whether or not it would track changes just as well if it were regular doc, odt... etc. files.

No comments:

Post a Comment