-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
executable file
·61 lines (56 loc) · 2.12 KB
/
utils.sh
File metadata and controls
executable file
·61 lines (56 loc) · 2.12 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# ##############################################################################
# Script Name : utils.sh
# Description : Common function for shell projects
# Author : Kevin GRILLET
# GitHub : https://github.com/kevingrillet/ShellUtils
# License : GNU GPL-3
# ##############################################################################
[ -n "${UTILS}" ] && return; UTILS=0; #pragma once
# Variables
DEBUG=0
VERBOSE=0
# ##############################################################################
# Function Name : execDebug
# Description : Execute <COMMAND> if $DEBUG >= 1
# Args : <COMMAND>
# ##############################################################################
execDebug() {
if [ "$#" -le 1 ] ; then echo "Usage: execDebug <COMMAND>" >&2; return 1; fi
if [ $DEBUG -ge 1 ]; then
"$@"
fi
}
# ##############################################################################
# Function Name : execVerbose
# Description : Show <COMMAND> stdout & stderr if $VERBOSE >= 1
# Args : <COMMAND>
# ##############################################################################
execVerbose() {
if [ "$#" -le 1 ] ; then echo "Usage: execVerbose <COMMAND>" >&2; return 1; fi
if [ $VERBOSE -ge 1 ]; then
"$@"
else
"$@" &>/dev/null
fi
}
# ##############################################################################
# Function Name : pause
# Description : Pause the script, wait an input from the user
# ##############################################################################
pause() {
read -s -r -n 1 -p "Press any key to continue..." >&1
echo "" >&1
}
# ##############################################################################
# Function Name : printVerbose
# Description : Show <MESSAGE> on stdout if $VERBOSE >= 1
# Args : <MESSAGE>
# Output : stdout <MESSAGE>
# ##############################################################################
printVerbose() {
if [ "$#" -ne 1 ] ; then echo "Usage: printVerbose <MESSAGE>" >&2; return 1; fi
if [ $VERBOSE -ge 1 ]; then
echo -e "$1" >&1
fi
}