From 4733072c7d90d8a16444c07b8b849b1ca20c0ca5 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Fri, 21 Mar 2025 09:33:02 +0100 Subject: [PATCH] dev: conditionally use --builtin in bash completion --- scripts/alr-completion.bash | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/alr-completion.bash b/scripts/alr-completion.bash index 9337e6b7..7d32a0c1 100755 --- a/scripts/alr-completion.bash +++ b/scripts/alr-completion.bash @@ -5,13 +5,26 @@ if ! builtin type -P alr &>/dev/null; then return fi +# Detect if --builtin is supported, by checking the version output by alr +# --version. Any version older than 2.2.0 will not support --builtin. +builtin="" +alr_version=$(alr --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) +if [[ -n "$alr_version" ]]; then + # Check if version is at least 2.2.0 + major=$(echo "$alr_version" | cut -d. -f1) + minor=$(echo "$alr_version" | cut -d. -f2) + if [[ $major -gt 2 ]] || [[ $major -eq 2 && $minor -ge 2 ]]; then + builtin="--builtin" + fi +fi + # Disable index auto-update to avoid interference with commands below if alr settings --global | grep -q index.auto_update= ; then update_period=$(alr settings --global | grep index.auto_update= | cut -f2 -d=) else update_period=unset fi -alr settings --global --set index.auto_update 0 +alr settings --global --set $builtin index.auto_update 0 # Commands/Topics: all line-first words not starting with capital letter, after # COMMANDS _alr_commands=$(alr | grep COMMANDS -A 99 | awk '{print $1}' | grep -v '[[:upper:]]' | xargs) @@ -91,5 +104,5 @@ complete -F _alr_completion alr # Re-enable index auto-update to avoid interference with commands below if [ "$update_period" != "unset" ]; then - alr settings --global --set index.auto_update $update_period + alr settings --global --set $builtin index.auto_update $update_period fi -- 2.39.5