diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2012-02-03 01:30:01 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2012-02-03 01:30:01 +0100 |
commit | fc2d9a48e9a5504f0ae4356278aa854cf2def1b1 (patch) | |
tree | 096a1a2479956be54e3859c553b93aade1dd41db /init.sh | |
parent | 1efc8a2e2f475c9cb4d353d02177ff6fd335b4a5 (diff) | |
download | vim4projects-fc2d9a48e9a5504f0ae4356278aa854cf2def1b1.tar.gz vim4projects-fc2d9a48e9a5504f0ae4356278aa854cf2def1b1.tar.xz vim4projects-fc2d9a48e9a5504f0ae4356278aa854cf2def1b1.zip |
init: modular approach
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'init.sh')
-rwxr-xr-x | init.sh | 128 |
1 files changed, 80 insertions, 48 deletions
@@ -1,75 +1,111 @@ #!/bin/sh -# Read README.txt first. # jpokorny@redhat.com -source ./init-functions - # -# categories of plugins + recipes to get them +# base functions # -common () { - announce "--- common ---" - # local_vimrc: - # directory-local settings applied to contained files (+requisite) - LOCAL_VIMRC_DIR="local-vimrc" - LOCAL_VIMRC_URL="http://lh-vim.googlecode.com/svn/misc/trunk/plugin/local_vimrc.vim" - LH_COMMON_URL="http://lh-vim.googlecode.com/svn/vim-lib/trunk/autoload/lh/common.vim" - # "plugin" directory has to be added (downloading recursively - # the whole original "plugin" path for one file is impractical) - do_wget $1 "$LOCAL_VIMRC_DIR/plugin" -nc "$LOCAL_VIMRC_URL" - do_wget $1 "$LOCAL_VIMRC_DIR/autoload/lh" -nc "$LH_COMMON_URL" +announce () { + # use colours if available + echo + if test -t 1; then + echo -en "\\033[32m" + echo -n "$1" + echo -e "\\033[0m" + else + echo "[[ $1 ]]" + fi } -python () { - announce "--- python ---" - # Python-mode: - # integrates pylint, rope, pydoc, pyflakes - # + extra highlighting, whitespace removal ... - do_git_submodule $1 "git-python-mode" +check_nargs () { + [ $1 -ge $2 ] + ret=$? + [ $ret -eq 0 ] || announce "action failed (expected $1+ args, got $2)" + return $ret } -tg2 () { - announce "--- tg2 ---" - # genshi-contrib: - # from genshi svn, contrib/vim - # TODO: is there a less complicated way to get these files? - GENSHI_CONTRIB_DIR="genshi-contrib" - GENSHI_CONTRIB_URL="http://svn.edgewall.org/repos/genshi/contrib/vim/" - do_wget $1 "$GENSHI_CONTRIB_DIR" -nc -e robots=off -r -l3 -np -nH --cut-dirs=4 -R index.html "$GENSHI_CONTRIB_URL" +check_ret () { + [ $1 -ne 0 ] && announce "action failed with exit status $1" + return $1 } -web () { - announce "--- web ---" - # empty for now +do_del () { + #echo "delete $1?" + [ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present" } -optional () { - announce "--- optional ---" - # makegreen: - # test results integration - # Tagbar (possible alternative TagList): - # "code navigator" incl. JS support if jsctags installed - do_git_submodule $1 "git-makegreen" "git-tagbar" +do_git_submodule () { + # usage: $1 = action, $2..n submodules + ret=0 + for submodule in "${@:2}"; do + announce "$1 $submodule (git submodule)" + if [ "$1" == "get" ]; then + git submodule update --init "$submodule" 2>&1 + else + do_del "$submodule" + fi + ret=$? + [ $ret -ne 0 ] && break + done + check_ret $ret +} + +do_wget () { + # usage: $1 = action, $2 = target dir, $3..n = actual arguments to wget + check_nargs $# 3 || return $? + if [ "$(dirname $2)" == "." ]; then + toplevel="$2" + else + toplevel="$(dirname $2)" + fi + announce "$1 $toplevel (wget)" + + if [ "$1" == "get" ]; then + wget --no-verbose --directory-prefix "$2" "${@:3}" 2>&1 + else + do_del "$toplevel" + fi + check_ret $? +} + +do_svn () { + # usage: $1 = action, $2 = target dir, $3 = svn repo (+ possibly args) + # TODO: support for revisions? + check_nargs $# 3 || return $? + if [ "$(dirname $2)" == "." ]; then + toplevel="$2" + else + toplevel="$(dirname $2)" + fi + announce "$1 $toplevel (svn)" + + if [ "$1" == "get" ]; then + svn checkout --force "${@:3}" "$2" 2>&1 + else + do_del "$toplevel" + fi + check_ret $? } # -# go +# source the choices (./init-* files) and go # -CHOICES="common|python|tg2|web|optional" +for choice in $(ls init-*); do [ -f $choice ] && source ./$choice; done +CHOICES=$(echo $CHOICES | sed 's/^|//') main () { action="get" if [ "$1" == "get" -o "$1" == "del" ]; then action="$1" - shift + [ $# -gt 1 ] && shift # || fall-through via unrecognized choice fi while [ -n "$1" ]; do eval "case \"$1\" in $CHOICES) $1 $action || exit $? - shift;; + shift + continue;; all) main $action $(echo $CHOICES | sed 's/|/ /g') break;; @@ -80,8 +116,4 @@ main () { done } -if [ $# -eq 0 ]; then - main help -else - main "$@" -fi +[ $# -eq 0 ] && main help || main "$@" |