Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created January 11, 2012 22:41
Show Gist options
  • Select an option

  • Save typeoneerror/1597223 to your computer and use it in GitHub Desktop.

Select an option

Save typeoneerror/1597223 to your computer and use it in GitHub Desktop.
Sup (short for svn update) is a quick application for updating subversion checkouts in a local directory from anywhere in your shell and opening the resulting updated project folder in TextMate.
#!/bin/bash
###########
# sup #
###########
#defaults
BASEDIR=`dirname ${BASH_SOURCE}`
CONFIG="${BASEDIR}/.sup-config"
IGNORE_EXTERNALS=0
IGNORE_TEXTMATE=0
SITES_PATH=.
VERBOSE=0
VERSION=1.0.0
do_exit()
{
echo -e "X $1"
exit 1
}
do_help()
{
cat << EOF
******************************************************************
* *
* sup, HELP! *
* *
******************************************************************
Sup (short for svn update) is a quick application for
updating subversion checkouts in a local directory from
anywhere in your shell and opening the resulting updated
project folder in TextMate.
Sup takes one parameter: the name of a directory that is
a subversion checkout. If you have not configured sup with
the -c sites path option, sup will look in the current
working directory as the default site path is "."
OPTIONS:
-c Specify path to your sites folder
FLAGS:
-h Show this message
-i Ignore externals in svn update call
-t Ignore open in Textmate Command
-v Verbose
-w Tells you where your sites folder has been configured
EXAMPLES:
#update a subversion repository in a folder called "Folder"
sup Folder
# update Folder but don't open in textmate
sup -t Folder
# update Folder without updating svn:externals
# then change directories into the updated directory
. sup -i Folder
VERSION: $0 ($VERSION)
AUTHOR: Ben Borowski <[email protected]>
EOF
}
do_log()
{
if [ $VERBOSE -eq 1 ]; then
echo -e ${1}
fi
}
do_options_parse()
{
source ${CONFIG}
if [ "${MY_SITES}" ]; then
SITES_PATH=$MY_SITES
fi
}
do_options_write()
{
echo "Default path changed to ${1} in ${CONFIG}"
echo "MY_SITES=${1}" > $CONFIG
}
if [ -f "${CONFIG}" ]; then
do_log "Parsing config file at ${CONFIG}"
do_options_parse
fi
# parse option flags
while getopts "c:hitvw" OPTION
do
# echo "$OPTION" $OPTIND $OPTARG
case $OPTION in
c)
do_options_write $OPTARG
exit
;;
h)
do_help
exit
;;
i)
IGNORE_EXTERNALS=1
;;
t)
IGNORE_TEXTMATE=1
;;
v)
VERBOSE=1
;;
w)
echo $SITES_PATH
exit
;;
?)
do_help
exit
;;
esac
done
# chop off the options
shift $(($OPTIND - 1))
# final path to site
SITE_TO_UPDATE=$SITES_PATH/${1}
# log
do_log "Ignore Textmate = ${IGNORE_TEXTMATE}"
do_log "Ignore Externals = ${IGNORE_EXTERNALS}"
do_log "Verbose = ${VERBOSE}"
do_log "\nAttempting to update ${SITE_TO_UPDATE}"
if [ -z "$1" ]; then
# didn't pass a path
# do_exit "Must supply a valid website folder argument"
do_help
exit
elif [ ! -d $SITE_TO_UPDATE ]; then
# folder didn't exist
do_exit "Specified directory \`${1}\` did not exist in ${SITES_PATH}\n Use the -c option to configure your sites root directory"
else
# do the subversion updates
if [ $IGNORE_EXTERNALS -eq 1 ]; then
# don't update externals
svn update --ignore-externals $SITE_TO_UPDATE
do_log "Updated ${SITE_TO_UPDATE} without externals"
else
# update all of it
svn update $SITE_TO_UPDATE
do_log "Updated ${SITE_TO_UPDATE} with externals"
fi
##
# Change into subdirectory that we updated.
# note that if you "source" the sup call, it will
# move you into the directory as well. example:
#
# @example
# $ source sup Folder
# $ . sup Folder
##
cd $SITE_TO_UPDATE
# open the project directory in textmate
if [ $IGNORE_TEXTMATE -eq 0 ]; then
do_log "Opening {$1} in Textmate..."
open -a TextMate.app .
fi
# clean up
do_log "\nDone."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment