Skip to content

Commit 0ffd8fc

Browse files
author
Thomas G.
committed
fix: 🐛 end of lines and colors
1 parent ed13668 commit 0ffd8fc

4 files changed

Lines changed: 80 additions & 82 deletions

File tree

src/common-utils/_normalize-json.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ help
2020

2121
# Check if JSON exists and is readable
2222
if test -z "$json" && test ! -f "$json"; then
23-
echo -e "${Red}JSON is missing${End}"
23+
echo -e "${Red}JSON is missing${End}" >&2
2424
exit 1
2525
fi
2626

@@ -106,14 +106,14 @@ get_path() {
106106
gsub("\\["; ".") | gsub("\\]"; "") | split(".") | map(
107107
select(length > 0) | gsub("^\"|\"$";"") | if test("^[0-9]+$") then tonumber else . end
108108
);
109-
getpath($path | split_path)'
109+
getpath($path | split_path)' 2>/dev/null
110110
}
111111

112112
# Function to get remove comments from JSON.
113113
# Do not remove comments inside strings.
114114
load_json() {
115115
local file=${1:--}
116-
sed -e 's:^[[:blank:]]*//.*$::g' $file
116+
sed -e 's:^[[:blank:]]*//.*$::g' $file 2>/dev/null
117117
}
118118

119119
load_json_schema() {
@@ -286,7 +286,7 @@ validate() {
286286
fi
287287

288288
# Log
289-
echo -e "${lvl}${Blue}Parsing schema <${path:-.}> == <${real:-.}>${None} at level <$level>\r" >&2
289+
echo -e "${lvl}${Blue}Parsing schema <${path:-.}> == <${real:-.}>${None} at level <$level>${End}" >&2
290290

291291
# get 1st level entry points (oneOf, allOf, anyOf, properties) and loop through them
292292
for entry in '"$id"' '"not"' '"oneOf"' '"allOf"' '"anyOf"' '"type"' '"required"' '"$ref"' '"properties"' '"items"' '"additionalProperties"'; do
@@ -296,7 +296,7 @@ validate() {
296296
continue
297297
fi
298298

299-
echo -e "${lvl}- Processing <${Blue}${path}:$entry${None}>\r" >&2
299+
echo -e "${lvl}- Processing <${Blue}${path}:$entry${None}>${End}" >&2
300300

301301
case $entry in
302302

@@ -323,24 +323,24 @@ validate() {
323323
fi
324324

325325
echo -e "${lvl}- Ref is ${Yellow}${ref}${End}" >&2
326-
echo -e "${lvl} From ${Yellow}${id}${None}...\r" >&2
326+
echo -e "${lvl} From ${Yellow}${id}${None}...${End}" >&2
327327

328328
# separate uri before # from fragment after #
329329
local uri=$(echo $ref | awk -F '#' '{print $1}')
330330
local fgt=$(echo $ref | awk -F '#' '{print $2}')
331331

332332
# if ref is a url, download it and use it as schema
333333
if test -n "$(echo $uri | grep -E '^http')"; then
334-
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...\r" >&2
334+
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...${End}" >&2
335335
schema=$(get_schema_json $uri)
336336
elif test -n "$uri"; then
337337
# check if file exists
338338
if test -f "$uri"; then
339-
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...\r" >&2
339+
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...${End}" >&2
340340
schema=$(load_json_schema $uri)
341341
elif test -n "$id"; then
342342
# load schema from file
343-
echo -e "${lvl}- Loading ${Yellow}$(dirname $id)/$uri${None}...\r" >&2
343+
echo -e "${lvl}- Loading ${Yellow}$(dirname $id)/$uri${None}...${End}" >&2
344344
schema=$(get_schema_json $(dirname $id)/$uri)
345345
else
346346
echo -e "${Red}Unable to resolve reference $ref with $id${End}" >&2
@@ -504,16 +504,16 @@ validate() {
504504
props=$(get_keys "$path.$entry" <<<"$schema" | tr "\n" " ")
505505

506506
# Log
507-
#echo -e "${lvl}- Properties are ${Purple}$props${End}" >&2
507+
#echo "${lvl}- Properties are ${Purple}$props${End}" >&2
508508

509509
# Loop through properties
510510
for prop in $props; do
511511

512-
#echo -e "${lvl}- Processing property ${Purple}$prop${End}" >&2
512+
#echo "${lvl}- Processing property ${Purple}$prop${End}" >&2
513513
if $not is_existing_path "$real.$prop" <<<"$json"; then
514514

515515
# Log
516-
echo -e "${lvl}- Processing <${Purple}$prop${None}>\r" >&2
516+
echo -e "${lvl}- Processing <${Purple}$prop${None}>${End}" >&2
517517

518518
# Parse sub schema
519519
if ! validate "$json" "$schema" "$path.$entry.$prop" "$real.$prop" "$path.$entry.$prop" "$not" "$level"; then
@@ -526,7 +526,7 @@ validate() {
526526
fi
527527
done
528528

529-
echo -e "${real:-.}"
529+
echo "${real:-.}"
530530
;;
531531

532532
\"additionalProperties\")
@@ -539,10 +539,10 @@ validate() {
539539
for prop in $(get_keys "$real" <<<"$json" | sort); do
540540

541541
if ! grep -q "$prop" <<<"$props"; then
542-
echo -e "${lvl}- Adding additional property <${Purple}$real.$prop${None}>\r" >&2
542+
echo -e "${lvl}- Adding additional property <${Purple}$real.$prop${None}>${End}" >&2
543543

544544
# Keep track of validated path
545-
echo -e "$real.$prop"
545+
echo "$real.$prop"
546546
fi
547547
done
548548
fi

src/common-utils/_zz_colors.sh

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
# Reset
2-
export None='\033[0m' # Text Reset
3-
export End='\033[0m\n' # Text Reset
2+
export None='\033[0m' # Text Reset
3+
export End='\033[0m\r' # Text Reset
44

55
# Regular Colors
6-
export Black='\033[0;30m' # Black
7-
export Red='\033[0;31m' # Red
8-
export Green='\033[0;32m' # Green
9-
export Yellow='\033[0;33m' # Yellow
10-
export Blue='\033[0;34m' # Blue
11-
export Purple='\033[0;35m' # Purple
12-
export Cyan='\033[0;36m' # Cyan
13-
export White='\033[0;37m' # White
6+
export Black='\033[0;30m' # Black
7+
export Red='\033[0;31m' # Red
8+
export Green='\033[0;32m' # Green
9+
export Yellow='\033[0;33m' # Yellow
10+
export Blue='\033[0;34m' # Blue
11+
export Purple='\033[0;35m' # Purple
12+
export Cyan='\033[0;36m' # Cyan
13+
export White='\033[0;37m' # White
1414

1515
# Bold
16-
export BBlack='\033[1;30m' # Black
17-
export BRed='\033[1;31m' # Red
18-
export BGreen='\033[1;32m' # Green
19-
export BYellow='\033[1;33m' # Yellow
20-
export BBlue='\033[1;34m' # Blue
21-
export BPurple='\033[1;35m' # Purple
22-
export BCyan='\033[1;36m' # Cyan
23-
export BWhite='\033[1;37m' # White
16+
export BBlack='\033[1;30m' # Black
17+
export BRed='\033[1;31m' # Red
18+
export BGreen='\033[1;32m' # Green
19+
export BYellow='\033[1;33m' # Yellow
20+
export BBlue='\033[1;34m' # Blue
21+
export BPurple='\033[1;35m' # Purple
22+
export BCyan='\033[1;36m' # Cyan
23+
export BWhite='\033[1;37m' # White
2424

2525
# Underline
26-
export UBlack='\033[4;30m' # Black
27-
export URed='\033[4;31m' # Red
28-
export UGreen='\033[4;32m' # Green
29-
export UYellow='\033[4;33m' # Yellow
30-
export UBlue='\033[4;34m' # Blue
31-
export UPurple='\033[4;35m' # Purple
32-
export UCyan='\033[4;36m' # Cyan
33-
export UWhite='\033[4;37m' # White
26+
export UBlack='\033[4;30m' # Black
27+
export URed='\033[4;31m' # Red
28+
export UGreen='\033[4;32m' # Green
29+
export UYellow='\033[4;33m' # Yellow
30+
export UBlue='\033[4;34m' # Blue
31+
export UPurple='\033[4;35m' # Purple
32+
export UCyan='\033[4;36m' # Cyan
33+
export UWhite='\033[4;37m' # White
3434

3535
# Background
36-
export On_Black='\033[40m' # Black
37-
export On_Red='\033[41m' # Red
38-
export On_Green='\033[42m' # Green
39-
export On_Yellow='\033[43m' # Yellow
40-
export On_Blue='\033[44m' # Blue
41-
export On_Purple='\033[45m' # Purple
42-
export On_Cyan='\033[46m' # Cyan
43-
export On_White='\033[47m' # White
36+
export On_Black='\033[40m' # Black
37+
export On_Red='\033[41m' # Red
38+
export On_Green='\033[42m' # Green
39+
export On_Yellow='\033[43m' # Yellow
40+
export On_Blue='\033[44m' # Blue
41+
export On_Purple='\033[45m' # Purple
42+
export On_Cyan='\033[46m' # Cyan
43+
export On_White='\033[47m' # White
4444

4545
# High Intensity
46-
export IBlack='\033[0;90m' # Black
47-
export IRed='\033[0;91m' # Red
48-
export IGreen='\033[0;92m' # Green
49-
export IYellow='\033[0;93m' # Yellow
50-
export IBlue='\033[0;94m' # Blue
51-
export IPurple='\033[0;95m' # Purple
52-
export ICyan='\033[0;96m' # Cyan
53-
export IWhite='\033[0;97m' # White
46+
export IBlack='\033[0;90m' # Black
47+
export IRed='\033[0;91m' # Red
48+
export IGreen='\033[0;92m' # Green
49+
export IYellow='\033[0;93m' # Yellow
50+
export IBlue='\033[0;94m' # Blue
51+
export IPurple='\033[0;95m' # Purple
52+
export ICyan='\033[0;96m' # Cyan
53+
export IWhite='\033[0;97m' # White
5454

5555
# Bold High Intensity
56-
export BIBlack='\033[1;90m' # Black
57-
export BIRed='\033[1;91m' # Red
58-
export BIGreen='\033[1;92m' # Green
59-
export BIYellow='\033[1;93m' # Yellow
60-
export BIBlue='\033[1;94m' # Blue
61-
export BIPurple='\033[1;95m' # Purple
62-
export BICyan='\033[1;96m' # Cyan
63-
export BIWhite='\033[1;97m' # White
56+
export BIBlack='\033[1;90m' # Black
57+
export BIRed='\033[1;91m' # Red
58+
export BIGreen='\033[1;92m' # Green
59+
export BIYellow='\033[1;93m' # Yellow
60+
export BIBlue='\033[1;94m' # Blue
61+
export BIPurple='\033[1;95m' # Purple
62+
export BICyan='\033[1;96m' # Cyan
63+
export BIWhite='\033[1;97m' # White
6464

6565
# High Intensity backgrounds
66-
export On_IBlack='\033[0;100m' # Black
67-
export On_IRed='\033[0;101m' # Red
68-
export On_IGreen='\033[0;102m' # Green
69-
export On_IYellow='\033[0;103m' # Yellow
70-
export On_IBlue='\033[0;104m' # Blue
71-
export On_IPurple='\033[0;105m' # Purple
72-
export On_ICyan='\033[0;106m' # Cyan
73-
export On_IWhite='\033[0;107m' # White
66+
export On_IBlack='\033[0;100m' # Black
67+
export On_IRed='\033[0;101m' # Red
68+
export On_IGreen='\033[0;102m' # Green
69+
export On_IYellow='\033[0;103m' # Yellow
70+
export On_IBlue='\033[0;104m' # Blue
71+
export On_IPurple='\033[0;105m' # Purple
72+
export On_ICyan='\033[0;106m' # Cyan
73+
export On_IWhite='\033[0;107m' # White

src/common-utils/devcontainer-feature.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "Common Utils",
3-
"version": "3.3.12",
3+
"version": "3.3.16",
44
"description": "Common utils for tomgrv/devcontainer-features",
55
"dependsOn": {
66
"ghcr.io/devcontainers/features/common-utils": {}
77
},
88
"id": "common-utils",
9-
"installsAfter": [
10-
"ghcr.io/devcontainers/features/common-utils"
11-
],
9+
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"],
1210
"options": {
1311
"utils": {
1412
"type": "string",
@@ -51,4 +49,4 @@
5149
]
5250
}
5351
}
54-
}
52+
}

src/common-utils/install.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ UTILS="${UTILS:-"jq dos2unix"}"
66
### Install utils
77
for bin in $UTILS; do
88

9-
echo "Checking $bin..." >&2
9+
echo "Checking $bin...${End}"
1010

1111
if [ -n "$(command -v $bin)" ]; then
12-
echo -e "$bin is installed."
12+
echo "$bin is installed.${End}"
1313
elif [ -f /etc/alpine-release ]; then
1414
apk update
1515
apk add $bin
@@ -19,10 +19,10 @@ for bin in $UTILS; do
1919
elif [ $(uname -o) = "Msys" ]; then
2020
winget install -s winget -e --name $bin --location /tmp/common-utils
2121
else
22-
echo "Please install $bin."
22+
echo "Please install $bin.${End}"
2323
exit 1
2424
fi
25-
done
25+
done >&2
2626

2727
# Prepare for installation
2828
ln -sf $PWD/$(dirname $0)/_zz_colors.sh $PWD/$(dirname $0)/zz_colors

0 commit comments

Comments
 (0)