Source code for /home/gipetto1/top-frog.com/public_html/script_src/files/tmbundle.sh

  1.  #! /bin/bash
  2.  # Script for updating TextMate bundles from SVN
  3.  # @author Shawn Parker
  4.  # @copyright none
  5.  #
  6.  # Written because the GetBundles bundle never seems to work right, no offense to its author...
  7.  # this follows suggestions made on the TextMate wiki for how to pull from the TextMate SVN
  8.  # http://macromates.com/textmate/manual/bundles#getting_more_bundles
  9.  #
  10.  # updated 2008-01-17
  11.  # fixed update function to work properly
  12.  # added 'list installed' option and the ability to update a single bundle only.
  13.  # see http://www.top-frog.com/archives/2008/01/17/tmbundle_update for more information
  14.  
  15.  # define some base vars
  16.  AS_TEXTMATE_DIR='/Library/Application Support/TextMate';
  17.  BUNDLE_DIR='Bundles';
  18.  SUPPORT_DIR='Support';
  19.  SVN_URL='http://macromates.com/svn/Bundles/trunk';
  20.  BUNDLE_EXT='.tmbundle';
  21.  UPDATE_SUPPORT=0;
  22.  
  23.  # set LC_TYPE to avoid encoding issues
  24.  export LC_CTYPE=en_US.UTF-8;
  25.  
  26.  # make sure we have our bundles svn directory
  27.  if ! [ -d "$AS_TEXTMATE_DIR/$BUNDLE_DIR" ]; then
  28.   if ! [ -d "$AS_TEXTMATE_DIR" ]; then
  29.   mkdir "$AS_TEXTMATE_DIR";
  30.   fi
  31.   mkdir "$AS_TEXTMATE_DIR/$BUNDLE_DIR";
  32.  fi
  33.  
  34.  # make sure an action is defined
  35.  if ! [ $1 ]; then
  36.   echo '';
  37.   echo 'Missing action. Options are [install | list | update]';
  38.   echo 'usage: ./tmbundle.sh install package.tmbundle';
  39.   echo ' ./tmbundle.sh list [installed]';
  40.   echo ' ./tmbundle.sh update [bundle]';
  41.   echo '';
  42.   echo 'note: encapsulate long names with spaces in quotes';
  43.   echo ' ./tmbundle.sh install "name with spaces.tmbundle"';
  44.   echo '';
  45.   exit 1;
  46.  fi
  47.  
  48.  # install bundle
  49.  if [ $1 = 'install' ]; then
  50.   # make sure we have our 2nd variable
  51.   if ! [ "$2" ]; then
  52.   echo '';
  53.   echo 'You must supply a bundle name to fetch for installs';
  54.   echo 'usage: ./tmbundle [install] [package.tmbundle]';
  55.   echo '';
  56.   exit 2;
  57.   fi
  58.  
  59.   # make sure we have a .tmbundle extention
  60.   if ! [ "${2##*.}" = 'tmbundle' ]; then
  61.   echo '';
  62.   echo 'invalid file extension or no file extension found';
  63.   echo "trying $2$BUNDLE_EXT";
  64.   BUNDLE="$2$BUNDLE_EXT";
  65.   else
  66.   BUNDLE=$2;
  67.   fi
  68.  
  69.   svn co "$SVN_URL/$BUNDLE_DIR/$BUNDLE" "$AS_TEXTMATE_DIR/$BUNDLE_DIR/$BUNDLE";
  70.   UPDATE_SUPPORT=1;
  71.  
  72.  # list installed bundles
  73.  elif [ $1 = 'list' ] || [ $1 = 'ls' ]; then
  74.   if ! [ "$2" ]; then
  75.   echo 'Listing available bundles:';
  76.   svn list "$SVN_URL/$BUNDLE_DIR";
  77.   else
  78.   echo 'Listing installed bundles:';
  79.   ls -1 "$AS_TEXTMATE_DIR/$BUNDLE_DIR";
  80.   fi
  81.  
  82.  # udpated bundles
  83.  elif [ $1 = 'update' ] || [ $1 = 'up' ]; then
  84.   # if no specific bundle specified, then update them all
  85.   if ! [ "$2" ]; then
  86.   echo "Updating Bundles:";
  87.   find "$AS_TEXTMATE_DIR/$BUNDLE_DIR" -maxdepth 1 -type d -name '*.tmbundle' -exec bash -c 'echo -n "${0##*/}: "; svn update "$0";' '{}' \;
  88.   RES=$?;
  89.   if ! [ RES = 0 ]; then
  90.   echo 'Bundles Updated';
  91.   else
  92.   echo "SVN failed with code: $RES";
  93.   fi
  94.   # update specific bundle
  95.   else
  96.   echo "Updating Bundle: $2";
  97.   # fix missing file extension
  98.   if ! [ "${2##*.}" = 'tmbundle' ]; then
  99.   echo '';
  100.   echo 'invalid file extension or no file extension found';
  101.   echo "trying $2$BUNDLE_EXT";
  102.   BUNDLE="$2$BUNDLE_EXT";
  103.   else
  104.   BUNDLE=$2;
  105.   fi
  106.  
  107.   # check to see if bundle is installed, if not, checkout instead of update
  108.   if [ -d "$AS_TEXTMATE_DIR/$BUNDLE_DIR/$BUNDLE" ]; then
  109.   svn update "$AS_TEXTMATE_DIR/$BUNDLE_DIR/$BUNDLE";
  110.   else
  111.   echo "Bundle $2 not installed - trying to install";
  112.   svn co "$SVN_URL/$BUNDLE_DIR/$BUNDLE" "$AS_TEXTMATE_DIR/$BUNDLE_DIR/$BUNDLE";
  113.   fi
  114.   fi
  115.   UPDATE_SUPPORT=1;
  116.  fi
  117.  
  118.  # make sure we have an up to date support folder
  119.  if [ $UPDATE_SUPPORT = 1 ]; then
  120.   echo -n 'Updating Support Folder: ';
  121.   # only do check out if support folder doesn't exist
  122.   if ! [ -d "$AS_TEXTMATE_DIR/$SUPPORT_DIR" ]; then
  123.   svn co "$SVN_URL/$SUPPORT_DIR" "$AS_TEXTMATE_DIR/$SUPPORT_DIR";
  124.   else
  125.   svn up "$AS_TEXTMATE_DIR/$SUPPORT_DIR";
  126.   fi
  127.  fi
  128.  
  129.  # tell TextMate to reload bundles
  130.  osascript -e 'tell app "TextMate" to reload bundles';
  131.  
  132.  # if we made it this far, exit (somewhat) gracefully
  133.  echo '';
  134.  echo 'action complete';
  135.  echo '';