summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/scripts/qmllint-entrypoints.sh
blob: 41c5a74090d52b1859673dab5b32da062a811393 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
set -euo pipefail

script_dir="$(
    CDPATH=''
    cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd
)"
repo_root="$(
    CDPATH=''
    cd -- "${script_dir}/../.." && pwd
)"
quickshell_dir="${repo_root}/quickshell"
qmlls_config="${quickshell_dir}/.qmlls.ini"

# Resolve qmllint: honour QMLLINT, then try common Qt 6 binary names and
# install paths, and finally bare qmllint. We need the Qt 6 build (>= 6.x)
# because older Qt 5 qmllint doesn't understand --ignore-settings / -W.
resolve_qmllint() {
    if [[ -n "${QMLLINT:-}" ]]; then
        printf '%s\n' "${QMLLINT}"
        return
    fi
    local candidate
    for candidate in qmllint6 qmllint-qt6 /usr/lib/qt6/bin/qmllint qmllint; do
        if command -v -- "${candidate}" >/dev/null 2>&1; then
            printf '%s\n' "${candidate}"
            return
        fi
    done
    return 1
}

if ! qmllint_bin="$(resolve_qmllint)"; then
    printf 'error: qmllint (Qt 6) not found in PATH (override with QMLLINT=/path/to/qmllint)\n' >&2
    exit 127
fi

print_broken_qmlls_link() {
    local target=""
    target="$(readlink -- "${qmlls_config}" 2>/dev/null || true)"
    printf 'error: %s is a broken symlink. lint-qml requires a live Quickshell tooling VFS.\n' "${qmlls_config}" >&2
    if [[ -n "${target}" ]]; then
        printf 'Broken target: %s\n' "${target}" >&2
    fi
    print_vfs_recovery
}

trim_ini_value() {
    local value="$1"
    value="${value#\"}"
    value="${value%\"}"
    printf '%s\n' "${value}"
}

read_ini_value() {
    local key="$1"
    local file="$2"
    local raw

    raw="$(sed -n "s/^${key}=//p" "${file}" | head -n 1)"
    if [[ -z "${raw}" ]]; then
        return 1
    fi

    trim_ini_value "${raw}"
}

print_vfs_recovery() {
    printf 'Generate it by starting the local shell config once, for example:\n' >&2
    printf '  dms -c %q run\n' "${quickshell_dir}" >&2
    printf '  qs -p %q\n' "${quickshell_dir}" >&2
}

if [[ -L "${qmlls_config}" && ! -e "${qmlls_config}" ]]; then
    print_broken_qmlls_link
    exit 1
fi

if [[ ! -e "${qmlls_config}" ]]; then
    printf 'error: %s is missing. lint-qml requires the Quickshell tooling VFS.\n' "${qmlls_config}" >&2
    print_vfs_recovery
    exit 1
fi

if ! build_dir="$(read_ini_value "buildDir" "${qmlls_config}")"; then
    printf 'error: %s does not contain a buildDir entry.\n' "${qmlls_config}" >&2
    print_vfs_recovery
    exit 1
fi

if ! import_paths_raw="$(read_ini_value "importPaths" "${qmlls_config}")"; then
    printf 'error: %s does not contain an importPaths entry.\n' "${qmlls_config}" >&2
    print_vfs_recovery
    exit 1
fi

if [[ ! -d "${build_dir}" || ! -f "${build_dir}/qs/qmldir" ]]; then
    printf 'error: Quickshell tooling VFS is missing or stale: %s\n' "${build_dir}" >&2
    print_vfs_recovery
    exit 1
fi

targets=(
    "${quickshell_dir}/shell.qml"
    "${quickshell_dir}/DMSShell.qml"
    "${quickshell_dir}/DMSGreeter.qml"
)

qmllint_args=(
    --ignore-settings
    -W 0
    -I "${build_dir}"
)

IFS=':' read -r -a import_paths <<< "${import_paths_raw}"
for path in "${import_paths[@]}"; do
    if [[ -n "${path}" ]]; then
        qmllint_args+=(-I "${path}")
    fi
done

if ! output="$("${qmllint_bin}" "${qmllint_args[@]}" "${targets[@]}" 2>&1)"; then
    printf '%s\n' "${output}" >&2
    exit 1
fi

if [[ -n "${output}" ]]; then
    printf '%s\n' "${output}"
fi