-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash-functions
More file actions
46 lines (40 loc) · 1016 Bytes
/
bash-functions
File metadata and controls
46 lines (40 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- mode: shell-script; coding: utf-8 -*-
# Common bash functions for Git helper scripts
# Abort on tool error (errorcode <> 0)
# Unless variable "EXEC_DO_NO_ABORT_ON_ERROR=true" is set
function abort_on_error() {
local err
err=$1
shift
if [[ $err -ne 0 ]]; then
echo "Program execution failed with error code $err!"
if [[ "$EXEC_DO_NO_ABORT_ON_ERROR" != "true" ]]; then
exit 1
fi
fi
}
# Execute this tool
# Caution: Use "\"text with spaces\"" to escape spaces
function exec_tool() {
echo "$@"
if [[ -z "${TESTMODE:-}" ]]; then
eval "$@"
abort_on_error $?
fi
}
# Execute this tool after confirmation
# Caution: Use \"text with spaces\" to escape spaces
function exec_tool_confirm() {
local go_on
echo -n "Execute (y/N): $@ "
read -n 1 go_on
echo
if [[ $go_on != "y" && $go_on != "Y" ]]; then
echo "Abort as requested"
exit
fi
if [[ -z "${TESTMODE:-}" ]]; then
eval "$@"
abort_on_error $?
fi
}