From 58ef8a8f42a68c7a81118ef9120705730ce3f458 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 11 Apr 2026 16:50:57 +0800 Subject: Add shell completion script generation feature --- mingling_core/tmpls/comps/bash.sh | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 mingling_core/tmpls/comps/bash.sh (limited to 'mingling_core/tmpls/comps/bash.sh') diff --git a/mingling_core/tmpls/comps/bash.sh b/mingling_core/tmpls/comps/bash.sh new file mode 100644 index 0000000..1af4f6c --- /dev/null +++ b/mingling_core/tmpls/comps/bash.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +_<<>>_bash_completion() { + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="" + [ $COMP_CWORD -gt 0 ] && prev="${COMP_WORDS[COMP_CWORD-1]}" + + local word_index=$((COMP_CWORD + 1)) + + local args=() + args+=(-f="${COMP_LINE//-/^}") + args+=(-C="$COMP_POINT") + args+=(-w="${cur//-/^}") + args+=(-p="${prev//-/^}") + args+=(-c="${COMP_WORDS[0]//-/^}") + args+=(-i="$word_index") + args+=(-F="bash") + + for word in "${COMP_WORDS[@]}"; do + args+=(-a="${word//-/^}") + done + + local suggestions + if suggestions=$(<<>> __comp "${args[@]}" 2>/dev/null); then + if [ $? -eq 0 ]; then + if [ "$suggestions" = "_file_" ]; then + compopt -o default + COMPREPLY=() + return + fi + + if [ -n "$suggestions" ]; then + local -a all_suggestions filtered + mapfile -t all_suggestions < <(printf '%s\n' "$suggestions") + + for suggestion in "${all_suggestions[@]}"; do + [ -z "$cur" ] || [[ "$suggestion" == "$cur"* ]] && filtered+=("$suggestion") + done + + [ ${#filtered[@]} -gt 0 ] && COMPREPLY=("${filtered[@]}") + return + fi + fi + fi + + COMPREPLY=() +} + +complete -F _<<>>_bash_completion <<>> -- cgit