Skip to content

Instantly share code, notes, and snippets.

@rbf
Created July 22, 2013 14:55
Show Gist options
  • Save rbf/6054457 to your computer and use it in GitHub Desktop.
Save rbf/6054457 to your computer and use it in GitHub Desktop.
Capture config for Sublime Text 2 into Dropbox, or install it to the current user if already captured.
#!/bin/sh
# The MIT License (MIT)
#
# Copyright (c) 2013 https://gist.github.com/rbf
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Inspired from:
# http://wheels.onebuttonapps.net/2012/04/use-dropbox-to-store-your-sublime-text-2-settings/
echo
echo "Please Make sure SUBLIME TEXT 2 is closed before continuing!"
echo
read -p "Press [ENTER] to continue..."
echo
SOURCE_SETUP_ITEM[0]="/Installed Packages"
SOURCE_SETUP_ITEM[1]="/Packages"
SOURCE_SETUP_ITEM[2]="/Pristine Packages"
SOURCE_SETUP_ITEM[3]="/Settings/License.sublime_license"
SOURCE_DIR="$(echo ~)/Dropbox/_home_work/dev/dotfiles/sublimetext2"
TARGET_DIR="$(echo ~)/Library/Application Support/Sublime Text 2"
BACKUP_DIR="${TARGET_DIR}/original-subl-folders"
echo "Creating backup dir: ${BACKUP_DIR}"
mkdir -vp "${BACKUP_DIR}"
echo
for i in "${SOURCE_SETUP_ITEM[@]}"
do
if [ ! -e "${SOURCE_DIR}/$(basename "${i}")" ]
then
echo "Capturing original ${i} to the Dropbox folder: ${SOURCE_DIR}/"
mkdir -vp "${SOURCE_DIR}"
cp -iR "${TARGET_DIR}${i}" "${SOURCE_DIR}/"
echo
fi
echo "Checking existent '${i}'..."
if [ -e "${TARGET_DIR}${i}" ]
then
echo "Moving original ${i} to the backup folder:"
mv -vi "${TARGET_DIR}${i}" "${BACKUP_DIR}"
fi
echo "Installing new '${i}' as a symbolic link..."
echo " - New file source dir: ${SOURCE_DIR}${i}"
echo " - Symbolic link target dir: ${TARGET_DIR}${i}"
ln -vis "${SOURCE_DIR}/$(basename "${i}")" "${TARGET_DIR}${i}"
echo
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment