repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

quickshell/nuguland/justfile

Raw
default:
  @just --list

# lint/typecheck/verify all Nuguland source; zero warnings
lint:
  #!/usr/bin/env bash
  set -euo pipefail
  tmp=$(mktemp -d)
  qs_pid=""
  cleanup() {
    [[ -z "$qs_pid" ]] || kill "$qs_pid" 2>/dev/null || true
    rm -rf "$tmp"
  }
  trap cleanup EXIT

  mapfile -t qml < <(find . -maxdepth 1 -name '*.qml' -print | sort)
  mapfile -t sh < <(find . -maxdepth 1 -name '*.sh' -print | sort)
  mapfile -t mjs < <(find . -name '*.mjs' -print | sort)
  mapfile -t frag < <(find shaders -name '*.frag' -print 2>/dev/null | sort)
  # qmllint receives -i /usr/lib/qt6/qml/Quickshell/**/*.qmltypes for Quickshell custom types.
  mapfile -t qmltypes < <(find /usr/lib/qt6/qml/Quickshell -name '*.qmltypes' -print | sort)
  qmltype_args=()
  for file in "${qmltypes[@]}"; do
    qmltype_args+=(-i "$file")
  done

  for file in "${qml[@]}"; do
    qmllint -I /usr/lib/qt6/qml "${qmltype_args[@]}" "$file" || { echo "qmllint failed: $file" >&2; exit 1; }
  done
  ((${#sh[@]} == 0)) || shellcheck "${sh[@]}"
  for file in "${mjs[@]}"; do
    node --check "$file"
  done
  ((${#frag[@]} == 0)) || glslangValidator "${frag[@]}"

  for file in "${qml[@]}"; do
    out="$tmp/${file#./}"
    qmlformat -n "$file" > "$out" || { echo "qmlformat failed: $file" >&2; exit 1; }
    cmp -s "$file" "$out" || { echo "qmlformat changed: $file" >&2; diff -u "$file" "$out"; exit 1; }
  done

  for file in "${sh[@]}"; do
    out="$tmp/${file#./}"
    shfmt "$file" > "$out"
    cmp -s "$file" "$out" || { diff -u "$file" "$out"; exit 1; }
  done

  shopt -s nullglob
  for shader in shaders/*.frag; do
    out="$tmp/${shader//\//__}.qsb"
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$out" "$shader"
    cmp -s "$shader.qsb" "$out" || { echo "stale shader blob: $shader.qsb" >&2; exit 1; }
  done
  for blob in shaders/*.qsb; do
    [[ -f "${blob%.qsb}" ]] || { echo "orphan shader blob: $blob" >&2; exit 1; }
  done
  if qs ipc -c nuguland call nuguland ping >/tmp/nuguland-lint.qs.out 2>/tmp/nuguland-lint.qs.err; then
    : > /tmp/nuguland-lint.qs.err
  else
    QT_NO_XDG_DESKTOP_PORTAL=1 qs -p shell.qml >/tmp/nuguland-lint.qs.out 2>/tmp/nuguland-lint.qs.err &
    qs_pid=$!
    sleep 3
    kill -0 "$qs_pid"
  fi
  if grep -E "WARN|ERROR|Error parsing|deprecated|Could not|failed" /tmp/nuguland-lint.qs.out /tmp/nuguland-lint.qs.err; then
    echo "runtime warnings during lint" >&2
    exit 1
  fi

# format Nuguland QML and shell scripts in place
fmt:
  #!/usr/bin/env bash
  set -euo pipefail
  mapfile -t qml < <(find . -maxdepth 1 -name '*.qml' -print | sort)
  mapfile -t sh < <(find . -maxdepth 1 -name '*.sh' -print | sort)
  for file in "${qml[@]}"; do
    qmlformat -i "$file" || { echo "qmlformat failed: $file" >&2; exit 1; }
  done
  ((${#sh[@]} == 0)) || shfmt -w "${sh[@]}"

# compile checked-in shaders
build:
  #!/usr/bin/env bash
  set -euo pipefail
  shopt -s nullglob
  for shader in shaders/*.frag; do
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$shader.qsb" "$shader"
  done