# shellcheck shell=bash
# completion.sh — bash-completion setup, stow-friendly
# Repo path: bashrc/.config/bash/completion.sh -> stows to ~/.config/bash/completion.sh
# Sourced from ~/.bashrc via: source_shell_file "${XDG_CONFIG_HOME:-$HOME/.config}/bash/completion.sh"
# Must be sourced BEFORE tool inits that register their own completions (zoxide/fzf).

[[ $- != *i* ]] && return 0

# Fallback if sourced standalone (normally provided by .bashrc)
declare -F has_tool >/dev/null 2>&1 || has_tool() { command -v "$1" >/dev/null 2>&1; }

# Source global definitions
if [ -f /etc/bashrc ]; then
    # shellcheck source=/dev/null
    . /etc/bashrc
fi

# Enable bash programmable completion features in interactive shells
if [ -f /usr/share/bash-completion/bash_completion ]; then
    # shellcheck source=/dev/null
    . /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
    # shellcheck source=/dev/null
    . /etc/bash_completion
fi
