forked from KinesisCorporation/Adv360-Pro-ZMK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_version.sh
More file actions
executable file
·72 lines (57 loc) · 2.08 KB
/
get_version.sh
File metadata and controls
executable file
·72 lines (57 loc) · 2.08 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
68
69
70
71
72
#!/usr/bin/env bash
# Get the date, first 4 chars of branch name and short commit hash
date=$(date -u +"%Y%m%d")
branch=${1:-$(git rev-parse --abbrev-ref HEAD | cut -c1-4)}
commit=${2:-$(git rev-parse --short HEAD)}
clique=${3:-"."}
uppercase_char() {
local char=$1
(echo $char | tr '[a-z]' '[A-Z]' 2> /dev/null) || echo "${char^^}"
}
# Function to transform characters to ZMK key behaviours
transform_char() {
local char=$1
if [[ $char =~ [A-Za-z] ]]; then
echo "<&kp $(uppercase_char $char)>, "
elif [[ $char =~ [0-9] ]]; then
echo "<&kp N${char}>, "
elif [ "$char" = "." ]; then
echo "<&kp DOT>, "
fi
}
# Iterate over the date and format characters
formatted_date=""
for ((i = 0; i < ${#date}; i++)); do
formatted_date+=$(transform_char "${date:$i:1}")
done
# Insert separator between date and branch
formatted_date+="<&kp MINUS>, "
# Iterate over the branch and format characters
formatted_branch=""
for ((i = 0; i < ${#branch}; i++)); do
formatted_branch+=$(transform_char "${branch:$i:1}")
done
# Insert separator between branch and commit hash
formatted_branch+="<&kp MINUS>, "
# Iterate over the commit hash and format characters
formatted_commit=""
for ((i = 0; i < ${#commit}; i++)); do
formatted_commit+=$(transform_char "${commit:$i:1}")
done
formatted_commit+="<&kp MINUS>, "
# Iterate over the clique string and format characters
formatted_clique=""
for ((i = 0; i < ${#clique}; i++)); do
formatted_clique+=$(transform_char "${clique:$i:1}")
done
# Combine the formatted string, add trailing carriage return
formatted_result="$formatted_date$formatted_branch$formatted_commit$formatted_clique"
formatted_result+="<&kp RET>"
echo $formatted_result
# Create new macro to define version, overwrite previous one
echo '#define VERSION_MACRO' > "config/version.dtsi"
echo 'macro_ver: macro_ver {' >> "config/version.dtsi"
echo 'compatible = "zmk,behavior-macro";' >> "config/version.dtsi"
echo '#binding-cells = <0>;' >> "config/version.dtsi"
echo "bindings = $formatted_result;" >> "config/version.dtsi"
echo '};' >> "config/version.dtsi"