-
Notifications
You must be signed in to change notification settings - Fork 4
/
convert_to_toml.sh
executable file
·88 lines (77 loc) · 2.36 KB
/
convert_to_toml.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# #<---------------------------->
# # You must include this section when:
# # Distributing, Using and/or Modifying this code.
# # Please read and abide by the terms of the included LICENSE.
# # Copyright 2024, Deepankar Chakroborty, All rights reserved.
# #
# # Version : 0.3
# # Author : Deepankar Chakroborty (https://github.com/dchakro)
# # Report issues: https://github.com/dchakro/alacritty_colors/issues
# # License: https://github.com/dchakro/alacritty_colors/blob/master/LICENSE
# #<---------------------------->
# # Get yj from: https://github.com/sclevine/yj
# shopt -s globstar
HELP()
{
printf 'This script allows you to covnert YAML formatted themes to TOML while changing some keywords
to ensure compatibility with contemporary release of alacritty.
Usage:
bash convert_to_toml.sh [options]
OPTIONS:
--help Show help
--dir Batch convert all files stored in themes/
--file FILE.yaml Convert input file
';
}
convertDir(){
cd themes
if command -v sd > /dev/null 2>&1; then
if command -v yj > /dev/null 2>&1; then
if /bin/ls | grep -Ei "yml$" &> /dev/null ; then
# For each .yaml file in the current directory
for yaml_file in *.yml; do
# Use basename to get the file name without the .yaml extension
base_name=$(basename "$yaml_file" .yml)
# Convert .yaml to .toml using yj
cat "$yaml_file" | yj -yt | sd "^.*_background.*\r?\n" "" | sd "^.*_foreground.*\r?\n" "" > "${base_name}.toml"
done
else
echo "No YAML files found in ./themes/"
fi
else
echo "Get yj from: https://github.com/sclevine/yj"
fi
else
echo "Get sd from: https://github.com/chmln/sd"
fi
}
convertFile(){
# checking for dependencies
if command -v sd > /dev/null 2>&1; then
if command -v yj > /dev/null 2>&1; then
yaml_file=${1}
# Use basename to get the file name without the .yaml extension
base_name=$(basename "$yaml_file" .yml)
# Convert .yaml to .toml using yj
cat "${yaml_file}" | yj -yt | sd "^.*_background.*\r?\n" "" | sd "^.*_foreground.*\r?\n" "" > "${base_name}.toml"
else
echo "Get yj from: https://github.com/sclevine/yj"
fi
else
echo "Get sd from: https://github.com/chmln/sd"
fi
}
if [ "$1" == "--help" ]; then
HELP
exit 0;
elif [ "$1" == "--dir" ]; then
convertDir
exit 0;
elif [ "$1" == "--file" ]; then
convertFile $2
exit 0;
else
HELP
exit 0;
fi