-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholiosource
More file actions
executable file
·67 lines (57 loc) · 1.94 KB
/
oliosource
File metadata and controls
executable file
·67 lines (57 loc) · 1.94 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
62
63
64
65
66
67
#!/bin/sh
# =============================================================================
# OlioSource
# =============================================================================
# -----------------------------------------------------------------------------
# Constants
# -----------------------------------------------------------------------------
FAILURE=1
PATH_DIR_TARGET="$(cd "$(dirname "$1}")" && pwd)"
NAME_FILE_TARGET="$(basename "$1")"
PATH_FILE_TARGET="${PATH_DIR_TARGET}/${NAME_FILE_TARGET}"
# -----------------------------------------------------------------------------
# Setup
# -----------------------------------------------------------------------------
# Temporary move to the target file directory
oldPathReturn="$(pwd)"
cd "$PATH_DIR_TARGET" || {
echo >&2 "No such directory. Path: ${PATH_DIR_TARGET}"
exit $FAILURE
}
trap 'cd "$oldPathReturn"' 0
# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------
excludeDisableComment() {
while IFS= read -r line; do
echo "${line}" | grep -v "^# shellcheck disable=SC1091"
done
}
excludeShebang() {
while IFS= read -r line; do
echo "$line" | grep -v "^#!"
done
}
isLineSourced() {
echo "$1" | grep -E '(\.|source)\s+.+' 1>/dev/null 2>/dev/null
}
traceLines() {
while IFS= read -r line; do
if (isLineSourced "$line"); then
file="$(echo "$line" | cut -d' ' -f2)"
excludeShebang <"$file"
else
echo "$line"
fi
done <"$1"
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
result=$(traceLines "$PATH_FILE_TARGET")
result=$(echo "$result" | excludeDisableComment)
if type shfmt 2>/dev/null 1>/dev/null; then
echo "$result" | shfmt -
exit $?
fi
echo "$result"