aboutsummaryrefslogtreecommitdiff
path: root/programs/cwal/components/vis.sh
blob: b241779d56357b57d37bde2e69cdd3ba572464a5 (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
#!/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=vis
export CWAL_COMPONENT

template="$CWAL_TEMPLATES_DIR/vis.lua"
configuration_directory="$HOME/.config/vis"
themes_directory="$configuration_directory/themes"
destination="$themes_directory/cwal.lua"

case ${1:-} in
detect)
    command -v vis >/dev/null 2>&1 && [[ -d $configuration_directory ]]
    ;;
prepare)
    require_readable 'vis template' "$template"
    mkdir -p -- "$themes_directory"
    ;;
generate)
    component_render theme "$destination" "$template"
    ;;
validate)
    temporary=$(component_temp_path theme)
    if command -v luac >/dev/null 2>&1 && ! luac -p -- "$temporary"; then
        printf 'apply-theme: generated vis theme is not valid Lua\n' >&2
        exit 1
    fi
    ;;
install)
    component_install theme "$destination"
    ;;
reload|summary)
    if [[ $1 == summary ]]; then
        printf '  vis:    %s (used on next launch)\n' "$destination"
    fi
    ;;
*)
    printf 'Usage: %s {detect|prepare|generate|validate|install|reload|summary}\n' \
        "${0##*/}" >&2
    exit 2
    ;;
esac