blob: 2b8197ca28357bf450d14bf2ac6a657edc4c20c3 (
plain)
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
|
#!/usr/bin/env bash
# Copyright (C) 2026 deltegui
# SPDX-License-Identifier: GPL-3.0-or-later
set -euo pipefail
component_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
source "$component_dir/common.sh"
CWAL_COMPONENT=btop
export CWAL_COMPONENT
template="$CWAL_TEMPLATES_DIR/btop.theme"
configuration_directory="$HOME/.config/btop"
themes_directory="$configuration_directory/themes"
theme_destination="$themes_directory/cwal.theme"
config_destination="$configuration_directory/btop.conf"
prepare_config()
{
local temporary
local mode=644
temporary=$(component_temp config "$config_destination")
if [[ -f $config_destination ]]; then
require_readable 'btop config' "$config_destination"
awk '
BEGIN { found = 0 }
/^[[:space:]]*color_theme[[:space:]]*=/ {
if (!found)
print "color_theme = \"cwal\""
found = 1
next
}
{ print }
END {
if (!found)
print "color_theme = \"cwal\""
}' "$config_destination" > "$temporary"
mode=$(stat -c '%a' "$config_destination" 2>/dev/null || printf '644')
else
printf 'color_theme = "cwal"\n' > "$temporary"
fi
chmod "$mode" "$temporary"
}
case ${1:-} in
detect)
command -v btop >/dev/null 2>&1 && [[ -d $configuration_directory ]]
;;
prepare)
require_readable 'btop template' "$template"
mkdir -p -- "$themes_directory"
prepare_config
;;
generate)
component_render theme "$theme_destination" "$template"
;;
validate)
;;
install)
component_install theme "$theme_destination"
component_install config "$config_destination"
;;
reload|summary)
if [[ $1 == summary ]]; then
printf ' btop: %s (theme cwal)\n' "$theme_destination"
fi
;;
*)
printf 'Usage: %s {detect|prepare|generate|validate|install|reload|summary}\n' \
"${0##*/}" >&2
exit 2
;;
esac
|