Skip to content

Commit 6692e1e

Browse files
committed
Embrace bash3+ functionality and opt out sed and grep
1 parent 0ea524d commit 6692e1e

File tree

4 files changed

+61
-27
lines changed

4 files changed

+61
-27
lines changed

git-labview-integration-posix/common_header.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
set -eu
1+
set -eu -o pipefail
22

33
function absolutize_posix_path {
44
local ORIG="$1"
55
local PWD_GIVEN=""
6-
if test "$#" -ge 2; then
6+
if (( "$#" > 2 )); then
77
PWD_GIVEN="$2"
88
else
99
PWD_GIVEN="$PWD"
1010
fi
11-
if test -n "$(echo "$ORIG" | grep -e '^["'"'"']*/+')"; then
11+
if [[ "${ORIG:0:1}" == "/" ]]; then
1212
echo "$ORIG"
13-
elif test -n "$(echo "$ORIG" | grep -e '^\s*["'"'"']*\.["'"'"']*\s*$')"; then
13+
elif [[ "$ORIG" == "." ]]; then
1414
echo "$PWD_GIVEN"
1515
else
1616
echo "$PWD_GIVEN/$ORIG"

git-labview-integration-posix/config_process_header.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
PROJECT_ROOT_FORCED=""
55

6-
if test -f "$CONFIGURATION_PATH_GIVEN" || test -l "$CONFIGURATION_PATH_GIVEN"; then
6+
if [[ -f "$CONFIGURATION_PATH_GIVEN" ]] || [[ -L "$CONFIGURATION_PATH_GIVEN" ]]; then
77
source "$CONFIGURATION_PATH_GIVEN"
88
else
9-
echo "Configuration file ($CONFIGURATION_PATH_GIVEN) not found"
9+
echo "Configuration file ($CONFIGURATION_PATH_GIVEN) not found" >&2
1010
exit 1
1111
fi
1212

1313
PROJECT_ROOT_POSIX=""
14-
if test -z "$PROJECT_ROOT_FORCED"; then
14+
if [[ -z "$PROJECT_ROOT_FORCED" ]]; then
1515
PROJECT_ROOT_POSIX="$(
1616
cd "$(dirname "$CONFIGURATION_SOURCE")"
17-
if test "${CONFIGURATION_DIRECTORY_LEVEL:-0}" -gt 0; then
17+
if (( CONFIGURATION_DIRECTORY_LEVEL )); then
1818
for i in {1.."$CONFIGURATION_DIRECTORY_LEVEL"}; do
1919
cd ..
2020
done
Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,64 @@
1-
set -eu
1+
set -eu -o pipefail
22

33
function windowsize_posix_path {
4-
echo $1 | sed -r 's/^(["'"'"']*)\/([A-Za-z])/\1\U\2:/' | sed 's/\//\\/g'
4+
if [[ "$1" =~ ^/[A-Za-z](/.*)?$ ]]; then
5+
local diskRegister
6+
diskRegister="$(echo "${1:1:1}" | tr '[:lower:]' '[:upper:]')"
7+
local tailPath
8+
# shellcheck disable=SC1003
9+
tailPath="$(echo "${1:2}" | tr '/' '\\')"
10+
if [[ -n "$tailPath" ]]; then
11+
if [[ "${tailPath:${#tailPath}-1:1}" == "\\" ]]; then
12+
tailPath="${tailPath:0:${#tailPath}-1}"
13+
fi
14+
else
15+
tailPath="\\"
16+
fi
17+
echo "${diskRegister}:${tailPath}"
18+
fi
519
}
620

721
function posixize_windows_path {
8-
echo $1 | sed -r 's/^(["'"'"']*)([A-Za-z]):/\1\/\L\2/' | sed 's/\\/\//g'
22+
if [[ "$1" =~ ^[A-Za-z]\: ]]; then
23+
local diskRegister
24+
diskRegister="$(echo "${1:0:1}" | tr '[:upper:]' '[:lower:]')"
25+
local tailPath
26+
# shellcheck disable=SC1003
27+
tailPath="$(echo "${1:2}" | tr '\\' '/')"
28+
if [[ -n "$tailPath" && "${tailPath:${#tailPath}-1:1}" == "/" ]]; then
29+
tailPath="${tailPath:0:${#tailPath}-1}"
30+
fi
31+
echo "/${diskRegister}${tailPath}"
32+
fi
933
}
1034

1135
function absolutize_windows_path {
1236
local ORIG="$1"
1337
local PWD_GIVEN=""
14-
if test "$#" -ge 2; then
38+
if (( "$#" > 2 )); then
1539
PWD_GIVEN="$2"
1640
else
1741
PWD_GIVEN="$PWD"
1842
fi
19-
if test -n "$(echo "$ORIG" | grep -e '^["'"'"']*[A-Za-z]:')"; then
20-
echo "$ORIG"
21-
else
22-
echo "$PWD_GIVEN\\$ORIG"
43+
local MODIFIED="$ORIG"
44+
if [[ "$ORIG" =~ ^[A-Za-z]\:\\+$ ]]; then
45+
if (( "${#ORIG}" == 2 )); then
46+
MODIFIED="${MODIFIED}\\"
47+
fi
48+
echo "$MODIFIED"
49+
return 0
50+
fi
51+
if [[ ! "$ORIG" =~ ^[A-Za-z]\:\\ ]]; then
52+
MODIFIED="$PWD_GIVEN\\$MODIFIED"
53+
fi
54+
if [[ "${MODIFIED:${#MODIFIED}-1:1}" == "\\" ]]; then
55+
MODIFIED="${MODIFIED:0:${#MODIFIED}-1}"
2356
fi
57+
echo "$MODIFIED"
2458
}
2559

2660
function fix_tool_input_path {
2761
local PATH_TO_FIX="$1"
28-
local PROJECT_ROOT_WINDOWS="${2}"
62+
local PROJECT_ROOT_WINDOWS="$2"
2963
absolutize_windows_path "$(windowsize_posix_path "$PATH_TO_FIX")" "$PROJECT_ROOT_WINDOWS"
3064
}

git-labview-integration-windows/config_process_header.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33

44
PROJECT_ROOT_FORCED=""
55

6-
if test -f "$CONFIGURATION_PATH_GIVEN" || test -l "$CONFIGURATION_PATH_GIVEN"; then
6+
if [[ -f "$CONFIGURATION_PATH_GIVEN" ]] || [[ -L "$CONFIGURATION_PATH_GIVEN" ]]; then
77
source "$CONFIGURATION_PATH_GIVEN"
88
else
9-
echo "Configuration file ($CONFIGURATION_PATH_GIVEN) not found"
9+
echo "Configuration file ($CONFIGURATION_PATH_GIVEN) not found" >&2
1010
exit 1
1111
fi
1212

13-
if test -z "$PROJECT_ROOT_FORCED"; then
13+
if [[ -z "$PROJECT_ROOT_FORCED" ]]; then
1414
PROJECT_ROOT_POSIX="$(
15-
cd "$(dirname "$CONFIGURATION_SOURCE")"
16-
if test "${CONFIGURATION_DIRECTORY_LEVEL:-0}" -gt 0; then
17-
for i in {1.."$CONFIGURATION_DIRECTORY_LEVEL"}; do
18-
cd ..
19-
done
20-
fi
21-
pwd
15+
cd "$(dirname "$CONFIGURATION_SOURCE")"
16+
if (( CONFIGURATION_DIRECTORY_LEVEL )); then
17+
for i in {1.."$CONFIGURATION_DIRECTORY_LEVEL"}; do
18+
cd ..
19+
done
20+
fi
21+
pwd
2222
)"
2323
PROJECT_ROOT_WINDOWS="$(windowsize_posix_path "$PROJECT_ROOT_POSIX")"
2424
else

0 commit comments

Comments
 (0)