4.5.0rc2 replaced the Agents panel with a compact one: a meter per limit, the percentage only on hover, no tokens by day or by model. noconnor.agents is a clone of omarchy.agents with Panel.qml, Main.qml and README.md from upstream v4.0.4, vendored as plain files in personal-desktop's config/ so the config step installs and captures it. capture.sh's plugin step skips plugins vendored that way instead of warning they aren't git checkouts. shell.json is synced from the live HP: the bar uses noconnor.agents, plus the 4.5 centerBegin/centerEnd layout, elsewhen and the antigravity plugin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
249 lines
11 KiB
Bash
Executable File
249 lines
11 KiB
Bash
Executable File
#!/bin/bash
|
|
# Pull the live machine's state back into this repo - the reverse of install.sh.
|
|
#
|
|
# Run it after customizing something by hand, then review `git diff` and commit.
|
|
# Each live file goes back into the layer that OWNS it for this machine's
|
|
# profile (the last layer providing that path; `./install.sh --show` lists
|
|
# them). It only refreshes paths the repo already tracks, so adding a newly
|
|
# customized file is a deliberate act (see README, "Adding a file").
|
|
#
|
|
# ./capture.sh # this machine's profile, every step
|
|
# ./capture.sh --profile hp-laptop # name it explicitly
|
|
# ./capture.sh config # only the named steps
|
|
# ./capture.sh --list
|
|
#
|
|
# Steps: config themes plugins bin services system packages
|
|
|
|
set -uo pipefail
|
|
|
|
REPO="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
STEPS=(config themes plugins bin services system packages)
|
|
|
|
c_ch=$'\033[33m'; c_skip=$'\033[2m'; c_warn=$'\033[33m'; c_err=$'\033[31m'; c_hd=$'\033[1m'; c_off=$'\033[0m'
|
|
[[ -t 1 ]] || { c_ch=; c_skip=; c_warn=; c_err=; c_hd=; c_off=; }
|
|
say() { printf '%s\n' "$*"; }
|
|
head_() { printf '\n%s==> %s%s\n' "$c_hd" "$*" "$c_off"; }
|
|
chg() { printf ' %sM %s%s\n' "$c_ch" "$*" "$c_off"; }
|
|
skip() { printf ' %s= %s%s\n' "$c_skip" "$*" "$c_off"; }
|
|
warn() { printf ' %s! %s%s\n' "$c_warn" "$*" "$c_off"; }
|
|
err() { printf ' %sx %s%s\n' "$c_err" "$*" "$c_off"; }
|
|
gone() { printf ' %s? %s%s\n' "$c_warn" "$*" "$c_off"; }
|
|
|
|
# shellcheck source=lib/layers.sh
|
|
source "$REPO/lib/layers.sh"
|
|
|
|
# pull_back <live> <repo-copy> <label>
|
|
pull_back() {
|
|
local live=$1 dest=$2 label=$3
|
|
if [[ ! -e $live ]]; then gone "$label - not on this machine any more"; return; fi
|
|
if cmp -s "$live" "$dest"; then skip "$label"; else cp "$live" "$dest"; chg "$label"; fi
|
|
}
|
|
|
|
# pull_tree <subdir> <live-root> -- every owned file under <layer>/<subdir>
|
|
pull_tree() {
|
|
local sub=$1 root=$2 rel layer
|
|
while IFS=$'\t' read -r rel layer; do
|
|
pull_back "$root/$rel" "$PROFILES/$layer/$sub/$rel" "$rel [$layer]"
|
|
done < <(owners "$sub")
|
|
}
|
|
|
|
step_config() { head_ "~/.config -> layers' config/"; pull_tree config "$HOME/.config"; }
|
|
step_bin() { head_ "~/.local/bin -> layers' bin/"; pull_tree bin "$HOME/.local/bin"; }
|
|
step_services() { head_ "systemd user units -> layers' systemd/"; pull_tree systemd/user "$HOME/.config/systemd/user"; }
|
|
step_system() { head_ "/etc drop-ins -> layers' system/"; pull_tree system /etc; }
|
|
|
|
step_themes() {
|
|
head_ "Themes"
|
|
local l t name live
|
|
declare -A theme=()
|
|
for l in "${LAYERS[@]}"; do
|
|
for t in "$PROFILES/$l"/themes/*/; do [[ -d $t ]] && theme[$(basename -- "$t")]=$l; done
|
|
done
|
|
for name in $(printf '%s\n' "${!theme[@]}" | sort); do
|
|
t="$PROFILES/${theme[$name]}/themes/$name/"
|
|
live="$HOME/.config/omarchy/themes/$name"
|
|
if [[ ! -d $live ]]; then gone "$name - no longer installed"; continue; fi
|
|
if diff -rq "$live" "$t" >/dev/null 2>&1; then
|
|
skip "$name [${theme[$name]}]"
|
|
else
|
|
rm -rf "$t"; mkdir -p "$t"; cp -r "$live/." "$t/"
|
|
chg "$name [${theme[$name]}]"
|
|
fi
|
|
done
|
|
# Flag themes installed by hand that no layer carries.
|
|
local lname
|
|
for l in "$HOME"/.config/omarchy/themes/*/; do
|
|
[[ -d $l ]] || continue
|
|
lname=$(basename -- "$l")
|
|
[[ -n ${theme[$lname]:-} ]] && continue
|
|
[[ -e "$l/.aether-managed" ]] && continue
|
|
[[ " ${P_AETHER[*]} " == *" $lname "* ]] && continue
|
|
warn "$lname is installed but in no layer (cp -r it into a layer's themes/ to track it)"
|
|
done
|
|
}
|
|
|
|
# Re-pin every plugin a layer lists to its live sha, drop the ones that are gone,
|
|
# and add live plugins no layer lists to the last layer that has a plugins.txt.
|
|
step_plugins() {
|
|
head_ "Plugin pins and local work"
|
|
local dir="$HOME/.config/omarchy/plugins" l f
|
|
local files=()
|
|
while IFS= read -r l; do files+=("$l"); done < <(layers_with plugins.txt)
|
|
if (( ! ${#files[@]} )); then skip "no layer carries plugins"; return 0; fi
|
|
|
|
declare -A listed=()
|
|
local id u s line tmp
|
|
for l in "${files[@]}"; do
|
|
f="$PROFILES/$l/plugins.txt"; tmp=$(mktemp)
|
|
while IFS= read -r line; do
|
|
if [[ -z $line || $line == \#* ]]; then printf '%s\n' "$line" >> "$tmp"; continue; fi
|
|
IFS=$'\t' read -r id u s <<<"$line"
|
|
listed[$id]=1
|
|
if [[ ! -d $dir/$id/.git ]]; then
|
|
gone "$id - no longer installed, dropped from $l/plugins.txt"
|
|
continue
|
|
fi
|
|
printf '%s\t%s\t%s\n' "$id" "$u" "$(git -C "$dir/$id" rev-parse HEAD)" >> "$tmp"
|
|
done < "$f"
|
|
if [[ $l == "${files[-1]}" ]]; then
|
|
local p
|
|
for p in "$dir"/*/; do
|
|
id=$(basename -- "$p")
|
|
[[ -n ${listed[$id]:-} ]] && continue
|
|
# Vendored as plain files under a layer's config/; step_config owns it.
|
|
[[ -n $(layers_with "config/omarchy/plugins/$id") ]] && continue
|
|
if [[ ! -d $p/.git ]]; then warn "$id is not a git checkout - not tracked"; continue; fi
|
|
if ! u=$(git -C "$p" remote get-url origin 2>/dev/null); then
|
|
warn "$id has no origin remote - push it somewhere before it can be pinned"; continue
|
|
fi
|
|
printf '%s\t%s\t%s\n' "$id" "$u" "$(git -C "$p" rev-parse HEAD)" >> "$tmp"
|
|
chg "$id - new, added to $l/plugins.txt"
|
|
done
|
|
fi
|
|
if cmp -s "$tmp" "$f"; then skip "$l/plugins.txt"; else mv "$tmp" "$f"; chg "$l/plugins.txt"; fi
|
|
rm -f "$tmp"
|
|
done
|
|
|
|
# Local plugin work, per layer: re-bundle 'local' branches, re-diff working
|
|
# trees, pull back --bin-- files. See install.sh step_plugins.
|
|
local b new p untracked
|
|
for l in "${LAYERS[@]}"; do
|
|
[[ -d $PROFILES/$l/plugin-patches ]] || continue
|
|
for b in "$PROFILES/$l"/plugin-patches/*.bundle; do
|
|
[[ -f $b ]] || continue
|
|
id=$(basename -- "$b" .bundle); p="$dir/$id"
|
|
[[ -d $p/.git ]] && git -C "$p" rev-parse --verify --quiet local >/dev/null || { gone "$id: no 'local' branch here"; continue; }
|
|
new="$b.new"
|
|
git -C "$p" bundle create "$new" origin/main..local >/dev/null 2>&1
|
|
# Bundles differ byte-wise run to run; compare the tips instead.
|
|
if [[ $(git -C "$p" bundle list-heads "$b" 2>/dev/null) == $(git -C "$p" bundle list-heads "$new" 2>/dev/null) ]]; then
|
|
rm -f "$new"; skip "$id.bundle [$l]"
|
|
else
|
|
mv "$new" "$b"; chg "$id.bundle [$l]"
|
|
fi
|
|
done
|
|
for f in "$PROFILES/$l"/plugin-patches/*-worktree.patch; do
|
|
[[ -f $f ]] || continue
|
|
id=$(basename -- "$f"); id=${id%-worktree.patch}; p="$dir/$id"
|
|
if [[ ! -d $p/.git ]]; then gone "$id - not installed"; continue; fi
|
|
tmp=$(mktemp)
|
|
git -C "$p" diff > "$tmp"
|
|
if cmp -s "$tmp" "$f"; then skip "$id-worktree.patch [$l]"; else mv "$tmp" "$f"; chg "$id-worktree.patch [$l]"; fi
|
|
rm -f "$tmp"
|
|
# Untracked files are not in a diff; only --bin-- files carry them.
|
|
while IFS= read -r untracked; do
|
|
[[ $untracked == bin/* && -f $PROFILES/$l/plugin-patches/$id--bin--${untracked#bin/} ]] && continue
|
|
warn "$id: untracked $untracked is not captured (bin/ files: cp to plugin-patches/$id--bin--<name>)"
|
|
done < <(git -C "$p" ls-files --others --exclude-standard)
|
|
done
|
|
for f in "$PROFILES/$l"/plugin-patches/*--bin--*; do
|
|
[[ -f $f ]] || continue
|
|
id=$(basename -- "$f")
|
|
pull_back "$dir/${id%%--bin--*}/bin/${id##*--bin--}" "$f" "${id%%--bin--*} bin/${id##*--bin--} [$l]"
|
|
done
|
|
done
|
|
}
|
|
|
|
# Report drift in the package delta without rewriting the hand-annotated files:
|
|
# each line carries a "why" comment that a regenerated list would lose.
|
|
step_packages() {
|
|
head_ "Package delta (report only)"
|
|
load_packages
|
|
local listed; listed=$(mktemp)
|
|
local e name archs cmds layer
|
|
for e in "${PKG_repo[@]}" "${PKG_aur[@]}" "${PKG_optional[@]}" "${PKG_ignore[@]}"; do
|
|
IFS=$PKG_FS read -r name archs cmds layer <<<"$e"; printf '%s\n' "$name"
|
|
done | sort -u > "$listed"
|
|
|
|
local baseline; baseline=$(mktemp)
|
|
{
|
|
pacman -Qi omarchy 2>/dev/null | awk '/^Depends On/{sub(/^Depends On *: /,"");print}' \
|
|
| tr ' ' '\n' | sed 's/[<>=].*//'
|
|
cat /usr/share/omarchy/install/omarchy-base.packages 2>/dev/null
|
|
} | grep -v '^$' | sort -u > "$baseline"
|
|
|
|
local untracked; untracked=$(pacman -Qqe 2>/dev/null | sort -u | comm -23 - "$baseline" | comm -23 - "$listed" | tr '\n' ' ')
|
|
local missing=()
|
|
for e in "${PKG_repo[@]}" "${PKG_aur[@]}"; do
|
|
IFS=$PKG_FS read -r name archs cmds layer <<<"$e"
|
|
pkg_applies "$archs" || continue
|
|
pacman -Qq "$name" &>/dev/null || pkg_cmd_present "$cmds" || missing+=("$name [$layer]")
|
|
done
|
|
|
|
if [[ -n ${untracked// } ]]; then
|
|
warn "installed but in no layer's packages.txt: $untracked"
|
|
say " add each to the layer it belongs to, or to $PROFILE/packages.txt [ignore]"
|
|
else
|
|
skip "nothing installed that the layers miss"
|
|
fi
|
|
(( ${#missing[@]} )) && warn "listed but not installed: ${missing[*]}"
|
|
say " packages.txt keeps a 'why' comment per package, so edit it by hand."
|
|
rm -f "$listed" "$baseline"
|
|
}
|
|
|
|
main() {
|
|
local want=() profile="" force=0 a
|
|
while (( $# )); do
|
|
a=$1; shift
|
|
case $a in
|
|
--profile|-p) profile=${1:?--profile needs a name}; shift ;;
|
|
--profile=*) profile=${a#*=} ;;
|
|
--force) force=1 ;;
|
|
--list|-l) printf '%s\n' "${STEPS[@]}"; exit 0 ;;
|
|
-h|--help) awk 'NR > 1 && /^#/ { sub(/^# ?/, ""); print; next } NR > 1 { exit }' "${BASH_SOURCE[0]}"; exit 0 ;;
|
|
-*) warn "unknown option: $a"; exit 2 ;;
|
|
*) if [[ " ${STEPS[*]} " == *" $a "* ]]; then want+=("$a"); else warn "unknown step: $a"; exit 2; fi ;;
|
|
esac
|
|
done
|
|
(( ${#want[@]} )) || want=("${STEPS[@]}")
|
|
|
|
local saved="" roles=""
|
|
if def=$(default_profile); then IFS=$'\t' read -r saved roles <<<"$def"; fi
|
|
[[ -n $profile ]] || profile=$saved
|
|
[[ -n $profile ]] || { err "no --profile given and none matches host $(hostname)"; exit 2; }
|
|
local rp; rp=$(find_layer "$profile") || { err "no such profile: $profile"; exit 2; }
|
|
[[ $rp == "$saved" ]] || roles=""
|
|
ROLES=(); [[ -n $roles ]] && IFS=', ' read -ra ROLES <<<"$roles"
|
|
|
|
# Before the first layered install, the live files still have the old shape
|
|
# (e.g. bindings in bindings.lua rather than hypr/layers/), and capturing them
|
|
# would write machine-specific content into shared layers like base/.
|
|
if [[ ! -f $STATE_FILE ]] && (( ! force )); then
|
|
err "no layered install recorded on this machine ($STATE_FILE)."
|
|
say " Run ./install.sh first, or --force and review the diff of shared layers by hand."
|
|
exit 2
|
|
fi
|
|
|
|
resolve "$rp" "${ROLES[@]}" || exit 2
|
|
load_settings
|
|
|
|
say "${c_hd}capture${c_off} profile=$PROFILE${ROLES:+ roles=${ROLES[*]}} host=$(hostname)"
|
|
# Canonical order whatever order they were named in: setup after config, etc.
|
|
for s in "${STEPS[@]}"; do [[ " ${want[*]} " == *" $s "* ]] && "step_$s"; done
|
|
|
|
head_ "Done"
|
|
say " Review with: git -C $REPO diff"
|
|
}
|
|
|
|
main "$@"
|