59 lines
2.8 KiB
Shell
Executable file
59 lines
2.8 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# The niri side: ~/.config/niri/caelestia.kdl (binds, autostart, window rules) and one
|
|
# include line in config.kdl, with a backup. The original deploys KWin scripts and
|
|
# systemd units here.
|
|
|
|
set -euo pipefail
|
|
source "$(dirname "${BASH_SOURCE[0]}")/lib/log.sh"
|
|
|
|
BIN="${CAELESTIA_BIN:-$HOME/.local/bin}"
|
|
export CAELESTIA_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/caelestia-niri"
|
|
|
|
echo
|
|
if [[ ! -x "$BIN/caelestia" ]]; then
|
|
skip "caelestia is not installed in $BIN; nothing to configure"
|
|
exit 0
|
|
fi
|
|
if [[ "${ASSUME_YES:-0}" != 1 ]]; then
|
|
read -r -p " Add the Caelestia keybinds and autostart to your niri config (a backup is made)? [Y/n] " r </dev/tty || r=""
|
|
[[ "${r:-y}" =~ ^[Yy] ]] || { skip "niri config left alone"; exit 0; }
|
|
fi
|
|
recommended=--recommended
|
|
[[ "${RECOMMENDED:-1}" == 1 ]] || recommended=
|
|
if [[ "${ASSUME_YES:-0}" != 1 ]]; then
|
|
read -r -p " Add the recommended niri settings: gaps, corners, input, animations (written once, yours to edit)? [Y/n] " r </dev/tty || r=""
|
|
[[ "${r:-y}" =~ ^[Yy] ]] || recommended=
|
|
fi
|
|
"$BIN/caelestia" niri install $recommended
|
|
|
|
# What comes after the include wins over it: another outputs file (DMS's dms/outputs.kdl) would
|
|
# undo Displays, and media, volume or brightness keys bound there would never reach the shell.
|
|
# Those lines stay as they are; the include moves below them, with a backup.
|
|
config="${XDG_CONFIG_HOME:-$HOME/.config}/niri/config.kdl"
|
|
at="$(grep -n '^[[:space:]]*include[[:space:]].*"caelestia\.kdl"' "$config" 2>/dev/null | head -1 | cut -d: -f1 || true)"
|
|
if [[ -n "$at" ]]; then
|
|
mapfile -t late < <(awk -v at="$at" 'NR > at && !/caelestia/ && /^[[:space:]]*(include[[:space:]].*outputs\.kdl|([A-Za-z_]+\+)*XF86(Audio|MonBrightness))/ { sub(/^[[:space:]]+/, ""); print NR ": " $0 }' "$config")
|
|
if ((${#late[@]})); then
|
|
info "These lines in config.kdl come after Caelestia's include and would win over it:"
|
|
printf ' %s\n' "${late[@]}"
|
|
r=y
|
|
if [[ "${ASSUME_YES:-0}" != 1 ]]; then
|
|
read -r -p " Move the include below them (a backup is made)? [Y/n] " r </dev/tty || r=""
|
|
fi
|
|
if [[ "${r:-y}" =~ ^[Yy] ]]; then
|
|
backup="$config.bak-caelestia-order"
|
|
cp -a "$config" "$backup"
|
|
line="$(sed -n "${at}p" "$config")"
|
|
sed -i "${at}d" "$config"
|
|
printf '%s\n' "$line" >>"$config"
|
|
if command -v niri >/dev/null 2>&1 && ! niri validate -c "$config" >/dev/null 2>&1; then
|
|
cp -a "$backup" "$config"
|
|
warn "niri refused the moved include, so config.kdl is back as it was"
|
|
else
|
|
ok "Caelestia's include is now last; the old file is $backup"
|
|
fi
|
|
else
|
|
skip "Include left where it is: Displays or the media keys may not take effect"
|
|
fi
|
|
fi
|
|
fi
|