Skip to content

Commit ae9c500

Browse files
committed
Add main script file.
1 parent 3337ff1 commit ae9c500

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

inline_source.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o errtrace -o nounset -o pipefail
4+
5+
inline_source() {
6+
source 'deps/includes/src/declare/declare.exit-codes.inc'
7+
source 'src/function.get_directory_path.sh'
8+
source 'src/function.get_file_from_string.sh'
9+
source 'src/function.get_file_path.sh'
10+
source 'src/function.replace_line_with_file_content.sh'
11+
12+
# @TODO: Create separate "handle_params" function
13+
# @TODO: Add usage/help message and params
14+
15+
if [[ $# -lt 1 || $1 == "" ]]; then
16+
echo 'One parameter expected: <source-file>' >&2
17+
exit "${EXIT_NOT_ENOUGH_PARAMETERS}"
18+
else
19+
local sSourceDirectory sSourceFilePath sTrimmedLine
20+
21+
readonly sSourceFilePath="$(get_file_path "${1}")"
22+
readonly sSourceDirectory=$(dirname "${sSourceFilePath}")
23+
24+
pushd "${sSourceDirectory}" > /dev/null || exit "${EXIT_COULD_NOT_FIND_DIRECTORY}"
25+
26+
while read -r; do
27+
# @NOTE: $REPLY is set by `read`
28+
sTrimmedLine="$(echo "${REPLY}" | xargs)"
29+
30+
if [[ "${sTrimmedLine:0:7}" = 'source ' && ${REPLY} != *\$* ]]; then
31+
replace_line_with_file_content "${REPLY}"
32+
else
33+
echo "${REPLY}"
34+
fi
35+
done < "${sSourceFilePath}"
36+
37+
popd > /dev/null 2>&1 || true
38+
fi
39+
}
40+
41+
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
42+
export -f inline_source
43+
else
44+
inline_source "${@-}"
45+
exit ${?}
46+
fi
47+
48+
# EOF

0 commit comments

Comments
 (0)