summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2012-02-02 17:10:26 +0100
committerJan Pokorný <jpokorny@redhat.com>2012-02-02 17:10:26 +0100
commitcb3cedc97e1e4cf81cd24017a3388ee82420e5cc (patch)
treeb12121cc66174f568309b0ba92a048071dd35db3
parent0e1373aaddb2903d23474a415f9e2be91ded7aed (diff)
downloadvim4projects-cb3cedc97e1e4cf81cd24017a3388ee82420e5cc.tar.gz
vim4projects-cb3cedc97e1e4cf81cd24017a3388ee82420e5cc.tar.xz
vim4projects-cb3cedc97e1e4cf81cd24017a3388ee82420e5cc.zip
init.sh + init-functions: split functions to extra file
that will be reused in a similar context Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--init-functions59
-rwxr-xr-xinit.sh67
2 files changed, 62 insertions, 64 deletions
diff --git a/init-functions b/init-functions
new file mode 100644
index 0000000..d3ce738
--- /dev/null
+++ b/init-functions
@@ -0,0 +1,59 @@
+# functions used by init.sh
+
+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
+}
+
+do_del () {
+ #echo "delete $1?"
+ [ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present"
+}
+
+do_wget () {
+ # usage: $1 = action, $2 = target dir, $2..n = actual arguments to wget
+ if [ $# -le 2 ]; then
+ echo "do_wget: not enough arguments"
+ exit 2
+ fi
+ if [ "$(dirname $2)" == "." ]; then
+ toplevel="$2"
+ else
+ toplevel="$(dirname $2)"
+ fi
+ announce "$1 $toplevel (wget)"
+
+ if [ "$1" == "get" ]; then
+ wget -nv -P "$2" "${@:3}" 2>&1
+ else
+ do_del "$toplevel"
+ fi
+ ret=$?
+ [ $ret -ne 0 ] && announce "action failed with exit status $?"
+ return $ret
+}
+
+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
+ [ $ret -ne 0 ] && announce "action failed with exit status $?"
+ return $ret
+}
diff --git a/init.sh b/init.sh
index 75d0133..653350e 100755
--- a/init.sh
+++ b/init.sh
@@ -2,69 +2,8 @@
# Read README.txt first.
# jpokorny@redhat.com
-#
-# helpers
-#
-
-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 ]]"
+source init-functions
- fi
-}
-
-do_del () {
- #echo "delete $1?"
- [ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present"
-}
-
-do_wget () {
- # usage: $1 = action, $2 = target dir, $2..n = actual arguments to wget
- if [ $# -le 2 ]; then
- echo "do_wget: not enough arguments"
- exit 2
- fi
- if [ "$(dirname $2)" == "." ]; then
- toplevel="$2"
- else
- toplevel="$(dirname $2)"
- fi
- announce "$1 $toplevel (wget)"
-
- if [ "$1" == "get" ]; then
- wget -nv -P "$2" "${@:3}" 2>&1
- else
- do_del "$toplevel"
- fi
- ret=$?
- [ $ret -ne 0 ] && announce "action failed with exit status $?"
- return $ret
-}
-
-git_init_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
- [ $ret -ne 0 ] && announce "action failed with exit status $?"
- return $ret
-}
-
-#
# categories of plugins + recipes to get them
#
@@ -86,7 +25,7 @@ python () {
# Python-mode:
# integrates pylint, rope, pydoc, pyflakes
# + extra highlighting, whitespace removal ...
- git_init_submodule $1 "git-python-mode"
+ do_git_submodule $1 "git-python-mode"
}
tg2 () {
@@ -110,7 +49,7 @@ optional () {
# test results integration
# Tagbar (possible alternative TagList):
# "code navigator" incl. JS support if jsctags installed
- git_init_submodule $1 "git-makegreen" "git-tagbar"
+ do_git_submodule $1 "git-makegreen" "git-tagbar"
}
#