Bash script to put your workspace on Dropbox

I have honestly never had my workspace version controlled before. I got a little tired of that so I finally made the effort to put it somewhere. I didn’t want an open source service nor did I want to pay, so I ended up getting Dropbox (https://www.dropbox.com/gs) to store my repo. I also didn’t want my entire workspace to be treated like a single git project, so I wrote a bash script that goes through any files you pass in and creates a git repo for them on Dropbox.

http://pastebin.com/GbMSABLF

Should be clear how to use. I’m not a Unix guru, so be gentle if I did something stupid. :slight_smile:

Also, I’m aware people will have a lot of objections to using Dropbox for source control, but I like the option. You can tailor this script to do it on a remote server or something if you want.

While I do a lot with (ba)sh but am surely no guru, maybe just some pointers.

  1. if you run the script from the ~ & pwd then it will work, otherwise you might have some problems.
    the first thing I always do is move to the location of the script, regardless where I am:

# $0 = path&filename of script file
# readlink get the real path of this file, not any symlinks or so
# dirname gives the path without the filename
_HOME_=$( dirname $(readlink -f $0 ))
pushd  ${_HOME_}

... # your code

popd

  1. as above, if you can pushd instead of cd, it is preferred, as it will make sure you can always return to the location you were before.
    If something goes wrong, you will want to return to a state you know.

  2. is there anything you need or would like to improve?

Otherwise I could not really complain. :smiley:

Ah, that pushd/popd is great, I’ll use that in the future.

One thing I did was


if [ -s 'Dropbox' ] ; then

and I tried to do:


if ![ -s 'Dropbox' ] ; then

but you can’t do that. How do you do not for one of these bracketed if statements? I couldn’t find any clear docs on how that syntax works and where -s -d etc. are specified. So I ended up just using the exists case along with an else, as you can see. However, I don’t think you need every single echo that I put in - some of them are there just because I needed to put something in the exists case.

Think that should be


if [ ! -s 'Dropbox' ] ; then

NB. spaces surrounding ‘!’ are important so that it shows as a separate argument.

Best wishes, Neil