blob: 47c240b1d0e2de8864aca14c4122023baef36fe3 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/bin/bash
#
# Templater basic functions.
#
# Initialize project
function __templater_init {
if [ ! -d "$PROJECT" ]; then
__templater_echo "Initializing $PROJECT..."
mkdir -p $PROJECT
fi
}
# Read a parameter from user
function __templater_ask {
local input
local function="$1"
local default="n"
shift 2
read -rep "Setup $function? (defaults to $default): " input
if [ "$input" == "y" ]; then
templater_$function
fi
}
# Return list of implementations
function __templater_implementations {
# Do not sort this list: the order in which functions are present in the code is important
#grep "^function templater_" $PROGRAM | cut -d ' ' -f 2 | sed -e 's/templater_//'
ls $SHARE
}
# Message
function __templater_echo {
#echo ""
echo "-> $*"
}
# Checkout to develop branch if available
function __templater_checkout_develop {
if git branch --list develop | grep -q develop; then
git checkout develop
fi
}
# Copy or append source file into destination
function __templater_copy_or_append {
local implementation="$1"
local file="$2"
if [ -z "$file" ]; then
return
fi
if [ ! -e "$file" ]; then
cp $SHARE/$implementation/files/$file .
elif ! grep -q -f $SHARE/$implementation/files/$file $file; then
cat $SHARE/$implementation/files/$file >> $file
fi
}
# Read a parameter from user
function __templater_user_input {
local input
local param="$1"
local default="$2"
shift 2
if echo $param | grep -q 'passwd'; then
read -s -rep "$* (defaults to $default): " input
else
read -rep "$* (defaults to $default): " input
fi
if [ -z "$input" ]; then
export $param="$default"
else
export $param="$input"
fi
}
# Install the global Makefile
function __templater_install_makefile {
if [ -z "$1" ]; then
return
fi
local src="$1"
local name="`basename $src`"
# First ensure we have the main Makefile
if [ ! -e "Makefile" ]; then
cp $SHARE/templater/files/Makefile .
fi
# Then copy the custom Makefile
if [ ! -e "$name" ]; then
cp $src .
fi
#if ! grep -q "^Makefile.local" .gitignore; then
# echo Makefile.local >> .gitignore
#fi
}
|