diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-01 16:43:16 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-01 18:55:15 +0200 |
| commit | caf53274f24377717ee0f9ac030f9159d9d336e6 (patch) | |
| tree | 128346a793e4287efa112a9224cd4040e8df523a /.local | |
| parent | 89a84956c27ea09f87051579288295e1ffde9b08 (diff) | |
| download | dotfiles-caf53274f24377717ee0f9ac030f9159d9d336e6.tar.gz dotfiles-caf53274f24377717ee0f9ac030f9159d9d336e6.zip | |
refactor(dotfiles): remove duplicated code
Diffstat (limited to '.local')
| -rwxr-xr-x | .local/bin/dotfiles | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/.local/bin/dotfiles b/.local/bin/dotfiles index 07b3a59..e953cd6 100755 --- a/.local/bin/dotfiles +++ b/.local/bin/dotfiles @@ -28,18 +28,22 @@ is_sync() { return 0 } -# sync_packs cmd packs… +# sync_packs cmd packages [sync-flag…] +# cmd → pacman or yay +# packages → nameref to an array containing a list of packages to sync +# sync_flag → additional flags to pass to cmd sync_packages() { local cmd="${1:?cmd argument missing}" - shift - local packs=("$@") + local -n packages="${2:?packages argument missing}" + shift 2 + local sync_args=("$@") local out_of_sync_deps=() - for dep in "${packs[@]}"; do + for dep in "${packages[@]}"; 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 "${out_of_sync_deps[@]}" + sudo "$cmd" --sync "${sync_args[@]}" "${out_of_sync_deps[@]}" fi } @@ -113,19 +117,14 @@ 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() { - 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 + # shellcheck disable=SC2034 + local proton_vpn_packages=(proton-vpn-gtk-app proton-vpn-cli) + sync_packages pacman proton_vpn_packages --assume-installed gnome-keyring } case ${1:-} in sync) + # shellcheck disable=SC2034 declare deps=( foot # terminal emulator tmux # terminal multiplexer @@ -155,9 +154,10 @@ sync) lua-language-server marksman ) - sync_packages pacman "${deps[@]}" + sync_packages pacman deps + # shellcheck disable=SC2034 declare aur_deps=(pass-secret-service-bin vim-language-server) - sync_packages yay "${aur_deps[@]}" + sync_packages yay aur_deps sync_proton_vpn sync_nvim sync_mdformat |
