2026-06-11 18:28:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Custom `bash` completions
|
|
|
|
|
#
|
|
|
|
|
# Sourced automatically by the `bash-completion` package at shell start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
complete -W '--force' dotfiles-install dotfiles-update
|
2026-08-23 15:28:56 +02:00
|
|
|
|
|
|
|
|
|
2026-08-03 09:36:33 +02:00
|
|
|
complete -W '--quieter' generate-shell-completions
|
|
|
|
|
|
|
|
|
|
|
2026-08-03 14:30:55 +02:00
|
|
|
_color_palette() {
|
|
|
|
|
local cur="$2" prev="$3"
|
|
|
|
|
local flags='--scheme --show --write'
|
|
|
|
|
|
|
|
|
|
# Values for `--scheme`, in both the "--scheme value"
|
|
|
|
|
# and the "--scheme=value" form
|
|
|
|
|
case "$prev" in
|
|
|
|
|
--scheme)
|
|
|
|
|
mapfile -t COMPREPLY < <(compgen -W 'dark light' -- "$cur")
|
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
=)
|
|
|
|
|
if [ "${COMP_WORDS[COMP_CWORD - 2]}" = "--scheme" ]; then
|
|
|
|
|
mapfile -t COMPREPLY < <(compgen -W 'dark light' -- "$cur")
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# Offer only flags not already on the line
|
|
|
|
|
local flag remaining=''
|
|
|
|
|
for flag in $flags; do
|
|
|
|
|
case " ${COMP_WORDS[*]} " in
|
|
|
|
|
*" $flag "*) ;;
|
|
|
|
|
*) remaining="$remaining $flag" ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$remaining" -- "$cur")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
complete -F _color_palette color-palette
|
|
|
|
|
|
|
|
|
|
|
2026-10-06 13:01:48 +02:00
|
|
|
# Fuzzy completion with the `**` trigger
|
|
|
|
|
# (e.g., `vi **<Tab>`, `ssh **<Tab>`)
|
|
|
|
|
#
|
|
|
|
|
# Must be sourced before `complete_alias` below,
|
|
|
|
|
# which then saves fzf's wrappers as the vanilla completions
|
2026-10-06 13:36:07 +02:00
|
|
|
#
|
|
|
|
|
# fzf's own host list globs ~/.ssh/config.d/*,
|
|
|
|
|
# which aborts under `failglob` if that folder is empty or missing
|
|
|
|
|
# => Use fzf's override hook with `bash-completion`'s host list instead
|
|
|
|
|
|
|
|
|
|
__fzf_list_hosts() {
|
|
|
|
|
local COMPREPLY=()
|
|
|
|
|
_known_hosts_real ''
|
|
|
|
|
printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-06 13:01:48 +02:00
|
|
|
if [ -r /usr/share/doc/fzf/examples/completion.bash ]; then
|
|
|
|
|
. /usr/share/doc/fzf/examples/completion.bash
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2026-08-23 15:28:56 +02:00
|
|
|
# Automagical completion for all ~/.config/shell/aliases
|
|
|
|
|
#
|
|
|
|
|
# See: https://github.com/cykerway/complete-alias
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC2034 # Read by complete_alias sourced below
|
|
|
|
|
COMPAL_AUTO_UNMASK=1
|
|
|
|
|
# shellcheck disable=SC1091 # Third-party file, not linted
|
|
|
|
|
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash/complete_alias"
|
|
|
|
|
|
|
|
|
|
if [ "${#BASH_ALIASES[@]}" -gt 0 ]; then
|
|
|
|
|
complete -F _complete_alias "${!BASH_ALIASES[@]}"
|
|
|
|
|
fi
|