Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 172 lines (128 sloc) 2.98 KB
#!/bin/sh
# "THE BEER-WARE LICENSE":
# Aldis Berjoza wrote this file. As long as you retain this
# notice you can do whatever you want with this stuff. If we meet some
# day, and you think this stuff is worth it, you can buy me a beer in
# return. <graudeejs@gmail.com>
case "`uname`" in
'FreeBSD')
FETCH_CMD='fetch'
ESED='sed -E'
;;
'OpenBSD')
FETCH_CMD='ftp'
ESED='sed -E'
;;
'Linux' | 'SunOS')
FETCH_CMD='wget'
ESED='sed -R'
;;
esac
USER_TMP="${USER_TMP:-/tmp}"
URL="$1"
shift
SERVICE="`echo "$URL" | sed -E -e 's#^http[s]?://##; s#/.*$##'`"
UPDATE_VIM_TAGS_DIR="$HOME/.vim"
BDIR="$HOME/.vim/bundle"
while [ "$1" ]; do
case "$1" in
'-d')
BDIR="$2"
shift
shift
;;
'-t')
TAG="$2"
shift
shift
;;
*)
echo "WARN: Unsupported option $2" > /dev/stderr
shift
esac
done
unsupported_service() {
echo "ERR: Unsupported service" > /dev/stderr
exit 1
}
plugin_path() {
case "$SERVICE" in
github.com)
echo "$URL" | $ESED -e 's#^http[s]?://github.com/##; s#/$##g'
;;
gitorious.org)
echo "$URL" | $ESED -e 's#^http[s]?://gitorious.org/##; s#/$##g'
;;
bitbucket.org)
echo "$URL" | $ESED -e 's#^http[s]?://bitbucket.org/##; s#src/?$##g; s#/$##g'
;;
*)
unsupported_service
;;
esac
}
plugin_name() {
plugin_path "$URL" | $ESED 's#^.*/##; s#^[vV][iI][mM]-##; s#(.)([A-Z])#\1_\2#g; s#[.-][vV][iI][mM]$##' | tr 'A-Z' 'a-z'
}
plugin_tag() {
case "$SERVICE" in
github.com )
if [ "$TAG" ]; then
echo "$TAG"
else
echo "master"
fi
;;
gitorious.org )
if [ "$TAG" ]; then
echo "$TAG"
else
echo "master"
fi
;;
bitbucket.org)
if [ "$TAG" ]; then
echo "$TAG"
else
echo "tip"
fi
;;
*)
unsupported_service
;;
esac
}
plugin_update() {
PLUGIN=`plugin_name`
REPO_PATH=`plugin_path`
[ -d "$BDIR/$PLUGIN" ] && mv "$BDIR/$PLUGIN" "$BDIR/$PLUGIN.bak"
case "$SERVICE" in
github.com)
$FETCH_CMD -o "$USER_TMP/$PLUGIN.tar.gz" "https://github.com/$REPO_PATH/tarball/`plugin_tag`"
;;
gitorious.org)
$FETCH_CMD -o "$USER_TMP/$PLUGIN.tar.gz" "https://gitorious.org/$REPO_PATH/archive-tarball/`plugin_tag`"
;;
bitbucket.org)
$FETCH_CMD -o "$USER_TMP/$PLUGIN.tar.gz" "https://bitbucket.org/$REPO_PATH/get/`plugin_tag`.tar.gz"
;;
*)
unsupported_service
;;
esac
if [ $? -eq 0 ]; then
PLUGIN_EXTRACT_PATH=`tar -tf "$USER_TMP/$PLUGIN.tar.gz" | head -n 1 | $ESED -e 's#^\./##; s#/.*$##'`
tar -xf "$USER_TMP/$PLUGIN.tar.gz" -C "$BDIR/"
if [ $? -eq 0 ]; then
mv "$BDIR/$PLUGIN_EXTRACT_PATH" "$BDIR/$PLUGIN"
rm -Rf "$BDIR/$PLUGIN.bak"
"${UPDATE_VIM_TAGS_DIR}/update_tags" "$BDIR/$PLUGIN"
else
rm -Rf "$BDIR/$PLUGIN_EXTRACT_PATH"
[ -d "$BDIR/$PLUGIN.bak" ] && mv "$BDIR/$PLUGIN.bak" "$BDIR/$PLUGIN"
fi
fi
[ -f "$USER_TMP/$PLUGIN.tar.gz" ] && rm -f "$USER_TMP/$PLUGIN.tar.gz"
}
[ -d "$BDIR" ] || mkdir "$BDIR"
[ "$URL" ] && plugin_update
Something went wrong with that request. Please try again.