aboutsummaryrefslogtreecommitdiff
path: root/generate_theme
blob: 451655db8504379eb4e8cd49bd324ba6852c7318 (plain) (blame)
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
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash

# shellcheck disable=SC2154

# Default mode
MODE="default"
# The directory of this script, so that this script can be called from anywhere
EXTENSION_DIRECTORY="$(dirname "${0}")"

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --mode)
            MODE="$2"
            shift 2
            ;;
        --list)
            echo "Available modes:"
            for template in "${EXTENSION_DIRECTORY}/templates"/*.json.template; do
                if [[ -f "$template" ]]; then
                    echo "  $(basename "$template" .json.template)"
                fi
            done
            exit 0
            ;;
        --help|-h)
            echo "Usage: $0 [--mode MODE] [--list]"
            echo ""
            echo "Options:"
            echo "  --mode MODE    Select theme mode (default: default)"
            echo "  --list         List available modes"
            echo "  --help, -h     Show this help"
            echo ""
            exit 0
            ;;
        *)
            echo "Unknown option: $1"
            echo "Use --help for usage information"
            exit 1
            ;;
    esac
done

# Your wal colour scheme file
WAL_COLOURS_FILE="${HOME}/.cache/wal/colors.json"
# The file to write the generated theme to, and that Zed will read
THEME_FILE="${EXTENSION_DIRECTORY}/themes/wal-theme.json"
# The template file for the selected mode (contains theme JSON with variable placeholders)
TEMPLATE_FILE="${EXTENSION_DIRECTORY}/templates/${MODE}.json.template"

# If the wal colour scheme file does not exist, exit with an error
if [[ ! -f "${WAL_COLOURS_FILE}" ]]; then
	echo "error: wal colourscheme file not found."
	exit 1
fi

# Check if mode file exists
if [[ ! -f "${TEMPLATE_FILE}" ]]; then
    echo "error: mode '${MODE}' not found. Available modes:"
    for template in "${EXTENSION_DIRECTORY}/templates"/*.json.template; do
        if [[ -f "$template" ]]; then
            echo "  $(basename "$template" .json.template)"
        fi
    done
    exit 1
fi

# Create the themes directory if it does not exist
mkdir -p "${EXTENSION_DIRECTORY}/themes"

# Extract wal colors and export them
eval "$(jq -r '
  .special as $special |
  .colors as $colors |
  "export background=\($special.background)
   export foreground=\($special.foreground)
   export cursor=\($special.cursor)
   export color0=\($colors.color0)
   export color1=\($colors.color1)
   export color2=\($colors.color2)
   export color3=\($colors.color3)
   export color4=\($colors.color4)
   export color5=\($colors.color5)
   export color6=\($colors.color6)
   export color7=\($colors.color7)
   export color8=\($colors.color8)
   export color9=\($colors.color9)
   export color10=\($colors.color10)
   export color11=\($colors.color11)
   export color12=\($colors.color12)
   export color13=\($colors.color13)
   export color14=\($colors.color14)
   export color15=\($colors.color15)"
  ' "${WAL_COLOURS_FILE}" || true)"

# Generate the Zed theme
envsubst < "${TEMPLATE_FILE}" > "${THEME_FILE}"

echo "zed theme generated with '${MODE}' mode: ${THEME_FILE}"