Skip to content

Instantly share code, notes, and snippets.

@NV
Created May 14, 2012 17:31
Show Gist options
  • Save NV/2695222 to your computer and use it in GitHub Desktop.
Save NV/2695222 to your computer and use it in GitHub Desktop.
Dropbox command-line shortcuts
#!/usr/bin/env ruby
BACKUP_ROOT = "#{ENV['HOME']}/Dropbox/Mac"
if ARGV.first
absolute_path = File.expand_path(ARGV.first)
puts(BACKUP_ROOT + absolute_path)
end
# Expanding paths in shell looks complicated so I wrote it in Ruby
# http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac

I have 2 Macbooks: one at work and one at home. I sync them using Dropbox. I sync lots of things: iTunes library, dotfiles, some ~/Library/Preferences/.

For example, I have a ~/.profile file in my home machine. I want to have the same file in my work machine. So I do the following:

$ cp ~/.profile ~/Dropbox/Mac/Users/nv/.profile 

On the work machine I do:

$ cp ~/Dropbox/Mac/Users/nv/.profile  ~/.profile

To save some typing, I’ve written a couple of scripts:

$ save .profile
/Users/nv/.profile -> /Users/nv/Dropbox/Mac/Users/nv/.profile
$ restore .profile
/Users/nv/Dropbox/Mac/Users/nv/.profile -> /Users/nv/.profile
#!/bin/sh
for arg in $@
do
BACKUP_PATH=`__get_backup_path.rb $arg`
if [[ -e $BACKUP_PATH ]]; then
cp -R -f -pv $BACKUP_PATH $arg
#TODO: consider using rsync
else
echo 'Cannot find: '$BACKUP_PATH
fi
done
#!/bin/sh
for arg in $@
do
if [[ -e $arg ]]; then
BACKUP_PATH=`__get_backup_path.rb $arg`
mkdir -pv `dirname $BACKUP_PATH`
cp -R -f -pv $arg $BACKUP_PATH
else
echo 'Cannot find: '$arg
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment