summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2012-02-09 10:56:48 +0100
committerJan Pokorný <jpokorny@redhat.com>2012-02-09 10:56:48 +0100
commite5fd48691defc1cda3e571aea4ca45ba7f377262 (patch)
treee0343a560b954c06ca0847354507e43e0b5c4ea8
parentc38a020c834bc0e9ba0dbbcbe94b422a774816bc (diff)
downloadvim4projects-e5fd48691defc1cda3e571aea4ca45ba7f377262.tar.gz
vim4projects-e5fd48691defc1cda3e571aea4ca45ba7f377262.tar.xz
vim4projects-e5fd48691defc1cda3e571aea4ca45ba7f377262.zip
init.sh: sync with a copy used in another context
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-xinit.sh69
1 files changed, 49 insertions, 20 deletions
diff --git a/init.sh b/init.sh
index 149cadc..b72b768 100755
--- a/init.sh
+++ b/init.sh
@@ -6,23 +6,44 @@
# internals
#
+CLR_OK=32
+CLR_BAD=31
+CLR_WRN=33
+
CHOICES=""
check_nargs () {
[ $1 -ge $2 ]
ret=$?
- [ $ret -eq 0 ] || announce "action failed (expected $1+ args, got $2)"
+ [ $ret -eq 0 ] || announce "action failed (expected $1+ args, got $2)" $CLR_BAD
return $ret
}
check_ret () {
- [ $1 -ne 0 ] && announce "action failed with exit status $1"
+ [ $1 -ne 0 ] && announce "action failed with exit status $1" $CLR_BAD
return $1
}
do_del () {
#echo "delete $1?"
- [ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present"
+ [ -d "$1" ] && rm -rfI -- "$1" || announce "$1 not present" $CLR_WRN
+}
+
+do_announce () {
+ # usage: see announce ($1, $3) + [$2 = colour (defaults to 32/green)]
+ # use colours if available
+ [ "$3" = "delimit" ] && echo
+ if test -t 1; then
+ colour=$2
+ if [ -z "$colour" ]; then
+ colour=$CLR_OK
+ fi
+ echo -en "\\033[${colour}m"
+ echo -n "$1"
+ echo -e "\\033[0m"
+ else
+ echo "[[ $1 ]]"
+ fi
}
#
@@ -31,20 +52,26 @@ do_del () {
register () {
# usage: $1=choice to register
- CHOICES="$CHOICES|$1"
+ CHOICES="$CHOICES|$1"
}
announce () {
- # usage: $1=message to output
- # use colours if available
- echo
- if test -t 1; then
- echo -en "\\033[32m"
- echo -n "$1"
- echo -e "\\033[0m"
- else
- echo "[[ $1 ]]"
+ # usage: $1=message to output [, $2 = start with extra newline if "delimit")]
+ do_announce "$1" $CLR_OK $2
+}
+
+require () {
+ # usage: $1=what is required [, $2=test (function/command)]
+ tester=$2
+ if [ -z "$tester" ]; then
+ tester=which
fi
+ $tester $1 >/dev/null
+ ret=$?
+ [ $ret -eq 0 ] \
+ && do_announce "require $1: checked ok" $CLR_OK \
+ || do_announce "require $1: not met" $CLR_BAD
+ return $ret
}
do_git_submodule () {
@@ -52,13 +79,13 @@ do_git_submodule () {
ret=0
git_prefix=$(git rev-parse --show-prefix)
for submodule in "${@:2}"; do
- announce "$1 $submodule (git submodule)"
+ announce "$1 $submodule (git submodule)" delimit
if [ "$1" == "get" ]; then
pushd "$(git rev-parse --show-toplevel)" 2>/dev/null
git submodule update --init --recursive "${git_prefix}${submodule}" 2>&1
popd 2>/dev/null
else
- do_del "$submodule"
+ do_del "$submodule" && return 64
fi
ret=$?
[ $ret -ne 0 ] && break
@@ -73,12 +100,12 @@ do_wget () {
if [ "$(dirname $2)" != "." ]; then
toplevel="$(dirname $2)"
fi
- announce "$1 $toplevel (wget)"
+ announce "$1 $toplevel (wget)" delimit
if [ "$1" == "get" ]; then
wget --no-verbose --no-clobber --execute robots=off \
--directory-prefix "$2" "${@:3}" 2>&1
else
- do_del "$toplevel"
+ do_del "$toplevel" && return 64
fi
check_ret $?
}
@@ -90,7 +117,7 @@ do_svn () {
if [ "$(dirname $2)" != "." ]; then
toplevel="$(dirname $2)"
fi
- announce "$1 $toplevel (svn)"
+ announce "$1 $toplevel (svn)" delimit
if [ "$1" == "get" ]; then
rev=""
if [ $# -ge 4 ]; then
@@ -98,7 +125,7 @@ do_svn () {
fi
svn checkout --force $rev "$3" "$2" | grep "revision"
else
- do_del "$toplevel"
+ do_del "$toplevel" && return 64
fi
check_ret $?
}
@@ -125,7 +152,9 @@ main () {
while [ -n "$1" ]; do
eval "case \"$1\" in
$CHOICES)
- $1 $action || exit $?
+ $1 $action
+ ret=$?
+ [ $ret -ne 0 ] && [ $ret -ne 64 ] && return $ret
shift
continue;;
all)