From 89a84956c27ea09f87051579288295e1ffde9b08 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Mon, 1 Jun 2026 16:23:51 +0200 Subject: fix(nvim): refactor dotfiles sync and make it sync outdated packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The installer (`dotfiles sync`) prompts the user to sync when packages are missing or out of date (previously only when missing). Refactor `sync_aur()` and `sync_deps()` → `sync_packs()` --- .local/bin/dotfiles | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/.local/bin/dotfiles b/.local/bin/dotfiles index 8b81475..07b3a59 100755 --- a/.local/bin/dotfiles +++ b/.local/bin/dotfiles @@ -15,25 +15,31 @@ clipboard_hint() { echo -e "Copied to clipboard:\n\n$cmd\n" } -sync_deps() { - local missing_deps=() - for dep; do - if ! pacman --query "$dep" >/dev/null 2>&1; then missing_deps+=("$dep"); fi - done - if [[ ${#missing_deps[@]} -eq 0 ]]; then return; fi - if prompt_for_install "Missing dependencies: ${missing_deps[*]}"; then - sudo pacman --sync "${missing_deps[@]}" +# is_sync cmd pack +# e.g.: is_sync pacman python-pipx +# return 0 → package is installed and up-to-date +# return 1 → package is not installed or out-of-date +is_sync() { + local cmd="${1:?cmd argument missing}" + local pack="${2:?pack argument missing}" + if ! "$cmd" --query "$pack" >/dev/null 2>&1 || "$cmd" --query --upgrades "$pack" >/dev/null 2>&1; then + return 1 fi + return 0 } -sync_aur() { - local missing_deps=() - for dep; do - if ! pacman --query "$dep" >/dev/null 2>&1; then missing_deps+=("$dep"); fi +# sync_packs cmd packs… +sync_packages() { + local cmd="${1:?cmd argument missing}" + shift + local packs=("$@") + local out_of_sync_deps=() + for dep in "${packs[@]}"; do + if ! is_sync "$cmd" "$dep"; then out_of_sync_deps+=("$dep"); fi done - if [[ ${#missing_deps[@]} -eq 0 ]]; then return; fi - if prompt_for_install "Missing AUR dependencies: ${missing_deps[*]}"; then - yay --sync "${missing_deps[@]}" + if ((${#out_of_sync_deps[@]} == 0)); then return; fi + if prompt_for_install "Out-of-sync packages: ${out_of_sync_deps[*]}"; then + sudo "$cmd" --sync "${out_of_sync_deps[@]}" fi } @@ -107,7 +113,15 @@ reinstall_nvim() { # So we just install it assuming gnome-keyring is installed, and it properly # picks up our secret service provider on the DBus. sync_proton_vpn() { - sudo pacman -S --assume-installed gnome-keyring proton-vpn-gtk-app proton-vpn-cli + local cmd=pacman + local out_of_sync_deps=() + for dep in proton-vpn-gtk-app proton-vpn-cli; do + if ! is_sync "$cmd" "$dep"; then out_of_sync_deps+=("$dep"); fi + done + if ((${#out_of_sync_deps[@]} == 0)); then return; fi + if prompt_for_install "Out-of-sync packages: ${out_of_sync_deps[*]}"; then + sudo "$cmd" --sync --assume-installed gnome-keyring "${out_of_sync_deps[@]}" + fi } case ${1:-} in @@ -141,12 +155,13 @@ sync) lua-language-server marksman ) - sync_deps "${deps[@]}" - sync_aur pass-secret-service-bin vim-language-server + sync_packages pacman "${deps[@]}" + declare aur_deps=(pass-secret-service-bin vim-language-server) + sync_packages yay "${aur_deps[@]}" + sync_proton_vpn sync_nvim sync_mdformat sync_claude - sync_proton_vpn ;; reinstall-nvim) reinstall_nvim ;; on) clipboard_hint "source $HOME/.local/share/dotfiles/dotfiles_on.env" ;; -- cgit v1.3.1