Skip to content

Instantly share code, notes, and snippets.

@davidmason
Forked from franklinjavier/sync.sh
Last active December 21, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmason/6238819 to your computer and use it in GitHub Desktop.
Save davidmason/6238819 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Set-up Sublime settings + packages sync over Dropbox
#
# Will sync settings + Installed plug-ins
#
# Tested on OSX - should support Linux too as long as
# you set-up correct SOURCE folder
#
# Copyright 2012 Mikko Ohtamaa http://opensourcehacker.com
# Licensed under WTFPL
#
# Note: If there is an existing installation in Dropbox,
# it will replace settings on a local computer
# No Warranty! Use on your own risk. Take backup of Library/Application Support/Sublime Text 2 folder first.
DROPBOX="$HOME/NotBackedUp/Dropbox"
# Where do we put Sublime settings in our Dropbox
SYNC_FOLDER="$DROPBOX/config/sublime-text-2"
# Where Sublime settings have been installed
if [ `uname` = "Darwin" ];then
SOURCE="$HOME/Library/Application Support/Sublime Text 2"
elif [ `uname` = "Linux" ];then
SOURCE="$HOME/.config/sublime-text-2"
else
echo "Unknown operating system"
exit 1
fi
# Check that settings really exist on this computer
if [ ! -e "$SOURCE/Packages/" ]; then
echo "Could not find $SOURCE/Packages/"
exit 1
fi
# Detect that we don't try to install twice and screw up
if [ -L "$SOURCE/Packages" ] ; then
echo "Dropbox packages already symlinked"
exit 1
fi
# Settings/ folder is not synced since .sublime_session files
# would cause unnecessary conflicts and traffic
# Dropbox has not been set-up on any computer before?
if [ ! -e "$SYNC_FOLDER" ] ; then
echo "Setting up Dropbox sync folder"
mkdir -p "$SYNC_FOLDER"
cp -r "$SOURCE/Installed Packages/" "$SYNC_FOLDER"
cp -r "$SOURCE/Packages/" "$SYNC_FOLDER"
cp -r "$SOURCE/Pristine Packages/" "$SYNC_FOLDER"
fi
# Now when settings are in Dropbox delete existing files
rm -rf "$SOURCE/Installed Packages"
rm -rf "$SOURCE/Packages"
rm -rf "$SOURCE/Pristine Packages"
# Symlink settings folders from Drobox
ln -s "$SYNC_FOLDER/Installed Packages" "$SOURCE"
ln -s "$SYNC_FOLDER/Packages" "$SOURCE"
ln -s "$SYNC_FOLDER/Pristine Packages" "$SOURCE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment