Skip to content

Commit 810eea0

Browse files
committed
tools: add gogh2moulti.bash.
1 parent f691884 commit 810eea0

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Although Moulti's Python packages, modules and functions are obviously available
1111
### Added
1212

1313
- Environment variables `MOULTI_ANSI` and `MOULTI_ANSI_THEME_*` provide (almost) full control over ANSI color themes.
14+
- `tools/gogh2moulti.bash` converts [Gogh themes](https://gogh-co.github.io/Gogh/) into `MOULTI_ANSI_THEME_*` variables.
1415

1516
### Changed
1617

Documentation.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,15 @@ The constant scrolling resumes when you hit the `End` key.
398398
# 8-color theme: specified colors are used as both regular and bright colors:
399399
MOULTI_ANSI_THEME_halfvga=bg=000000,fg=AAAAAA,ansi=000000:AA0000:00AA00:AA5500:0000AA:AA00AA:00AAAA:AAAAAA
400400
```
401-
Moulti does not take bg (background) and fg (foreground) into account for the time being.
402-
Colors may be prefixed with `#`; hexadecimal digits may be specified as lower or uppercase but there must be exactly 6 digits; theme names are case-sensitive.
401+
Manually defining `MOULTI_ANSI_THEME_*` can be painful. So have a look at this helper script that turns [Gogh themes](https://gogh-co.github.io/Gogh/) into such variables:
402+
```shell
403+
./tools/gogh2moulti.bash
404+
```
405+
Other details:
406+
- Moulti does not take `bg` (background) and `fg` (foreground) into account for the time being.
407+
- Colors may be prefixed with `#`.
408+
- Hexadecimal digits may be specified as lower or uppercase but there must be exactly 6 digits.
409+
- Theme names are case-sensitive: if you define `MOULTI_ANSI_THEME_AlphaBeta`, be sure to mention e.g. `MOULTI_ANSI=dark=AlphaBeta`, not `MOULTI_ANSI=dark=ALPHABETA`.
403410
- `MOULTI_CUSTOM_CSS`: absolute filepath to a custom TCSS file; see "How to define my own step classes ?"
404411
- `MOULTI_PASS_CONCURRENCY`: define how many concurrent "moulti pass" commands is acceptable; defaults to 20.
405412
- `MOULTI_SAVE_PATH`: base path under which export directories are created when saving a Moulti instance; defaults to `.` i.e. the instance's current working directory.

tools/gogh2moulti.bash

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# Convert Gogh themes (YAML) to MOULTI_ANSI_THEME_* environment variables.
3+
# Launched without any argument: get the Gogh Git repository and convert all its themes.
4+
# Launched with at least one argument: assume all arguments are filepaths and attempt to convert them.
5+
6+
function extract {
7+
grep -o -P "${1}"':.*#[0-9A-Fa-f]{6}' "${2}"
8+
}
9+
10+
function just_the_color_please {
11+
grep -o -P '[0-9A-Fa-f]{6}$'
12+
}
13+
14+
function gogh_theme_yaml_to_moulti_env_var {
15+
local file name bg fg colors
16+
file="${1}"
17+
name=$(basename "${file}" '.yml' | sed 's/[^A-Za-z0-9_]/_/g')
18+
bg=$(extract 'background' "${file}" | just_the_color_please)
19+
fg=$(extract 'foreground' "${file}" | just_the_color_please)
20+
readarray -t colors < <(extract 'color_(0[1-9]|1[0-6])' "${file}" | sort | just_the_color_please)
21+
local IFS=':'
22+
printf 'export MOULTI_ANSI_THEME_%s=bg=%s,fg=%s,ansi=%s\n' "${name}" "${bg}" "${fg}" "${colors[*]}"
23+
}
24+
25+
function gogh_theme_yaml_to_moulti_env_var_loop {
26+
for file in "$@"; do
27+
gogh_theme_yaml_to_moulti_env_var "${file}"
28+
done
29+
}
30+
31+
function gogh2moulti_main {
32+
[ -d gogh ] || git clone https://github.com/Gogh-Co/Gogh.git gogh
33+
gogh_theme_yaml_to_moulti_env_var_loop gogh/themes/*.yml
34+
}
35+
36+
# Sourcing this file? Stop here.
37+
return 2> /dev/null
38+
39+
set -e
40+
if [ $# -eq 0 ]; then
41+
gogh2moulti_main
42+
else
43+
gogh_theme_yaml_to_moulti_env_var_loop "$@"
44+
fi

0 commit comments

Comments
 (0)