โค้ดต่อไปนี้ดัดแปลงจากคำตอบของ Stack Overflowและกระทู้สนทนาของ Ubuntu Forumsนี้จะเพิ่มความสมบูรณ์สำหรับนามแฝงที่คุณกำหนดไว้ทั้งหมด:
# Automatically add completion for all aliases to commands having completion functions
function alias_completion {
    local namespace="alias_completion"
    # parse function based completion definitions, where capture group 2 => function and 3 => trigger
    local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
    # parse alias definitions, where capture group 1 => trigger, 2 => command, 3 => command arguments
    local alias_regex="alias ([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
    # create array of function completion triggers, keeping multi-word triggers together
    eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
    (( ${#completions[@]} == 0 )) && return 0
    # create temporary file for wrapper functions and completions
    rm -f "/tmp/${namespace}-*.tmp" # preliminary cleanup
    local tmp_file; tmp_file="$(mktemp "/tmp/${namespace}-${RANDOM}XXX.tmp")" || return 1
    local completion_loader; completion_loader="$(complete -p -D 2>/dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"
    # read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
    local line; while read line; do
        eval "local alias_tokens; alias_tokens=($line)" 2>/dev/null || continue # some alias arg patterns cause an eval parse error
        local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
        # skip aliases to pipes, boolean control structures and other command lists
        # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
        eval "local alias_arg_words; alias_arg_words=($alias_args)" 2>/dev/null || continue
        # avoid expanding wildcards
        read -a alias_arg_words <<< "$alias_args"
        # skip alias if there is no completion function triggered by the aliased command
        if [[ ! " ${completions[*]} " =~ " $alias_cmd " ]]; then
            if [[ -n "$completion_loader" ]]; then
                # force loading of completions for the aliased command
                eval "$completion_loader $alias_cmd"
                # 124 means completion loader was successful
                [[ $? -eq 124 ]] || continue
                completions+=($alias_cmd)
            else
                continue
            fi
        fi
        local new_completion="$(complete -p "$alias_cmd")"
        # create a wrapper inserting the alias arguments if any
        if [[ -n $alias_args ]]; then
            local compl_func="${new_completion/#* -F /}"; compl_func="${compl_func%% *}"
            # avoid recursive call loops by ignoring our own functions
            if [[ "${compl_func#_$namespace::}" == $compl_func ]]; then
                local compl_wrapper="_${namespace}::${alias_name}"
                    echo "function $compl_wrapper {
                        (( COMP_CWORD += ${#alias_arg_words[@]} ))
                        COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1})
                        (( COMP_POINT -= \${#COMP_LINE} ))
                        COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
                        (( COMP_POINT += \${#COMP_LINE} ))
                        $compl_func
                    }" >> "$tmp_file"
                    new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
            fi
        fi
        # replace completion trigger by alias
        new_completion="${new_completion% *} $alias_name"
        echo "$new_completion" >> "$tmp_file"
    done < <(alias -p | sed -Ene "s/$alias_regex/\1 '\2' '\3'/p")
    source "$tmp_file" && rm -f "$tmp_file"
}; alias_completion
สำหรับ simple (คำสั่งเท่านั้นไม่มีอาร์กิวเมนต์) alias จะกำหนดฟังก์ชันการทำให้สมบูรณ์ต้นฉบับให้กับนามแฝง สำหรับนามแฝงที่มีข้อโต้แย้งมันจะสร้างฟังก์ชั่น wrapper ที่แทรกอาร์กิวเมนต์พิเศษลงในฟังก์ชั่นการเติมเต็มให้สมบูรณ์
ซึ่งแตกต่างจากสคริปก็มีการพัฒนาจากคำพูดที่ฟังก์ชั่นประการทั้งสำหรับคำสั่งนามแฝงและข้อโต้แย้งของมัน ( แต่อดีตจะต้องมีการจับคู่โดยคำสั่งเสร็จและไม่สามารถซ้อนกัน) และมันน่าเชื่อถือควรกรองนามแฝงที่จะแสดงรายการคำสั่งและไพพ์ (ซึ่งถูกข้ามเนื่องจากเป็นไปไม่ได้ที่จะค้นหาสิ่งที่จะทำให้สมบูรณ์โดยไม่ต้องสร้างตรรกะบรรทัดคำสั่งการแยกวิเคราะห์เชลล์ใหม่อีกครั้ง)
การใช้
บันทึกรหัสเป็นไฟล์เชลล์สคริปต์และแหล่งที่มาหรือคัดลอกฟังก์ชันขายส่งใน.bashrc(หรือไฟล์จุดที่เกี่ยวข้องของคุณ) สิ่งสำคัญคือการเรียกใช้ฟังก์ชั่นหลังจากตั้งค่า bash เสร็จสมบูรณ์และ alias แล้ว (โค้ดด้านบนเรียกใช้ฟังก์ชั่นได้ทันทีหลังจากคำจำกัดความใน "แหล่งที่มาและลืม" วิญญาณ แต่คุณสามารถย้ายสายที่ใดก็ได้ถ้าเป็นเช่นนั้น เหมาะกับคุณดีกว่า) หากคุณไม่ต้องการฟังก์ชั่นในสภาพแวดล้อมของคุณหลังจากที่มันออกไปคุณสามารถเพิ่มunset -f alias_completionหลังจากเรียกมัน
หมายเหตุ
หากคุณใช้bash4.1 หรือสูงกว่าและใช้ความสำเร็จที่โหลดแบบไดนามิกสคริปต์จะพยายามโหลดความสำเร็จสำหรับคำสั่งนามแฝงทั้งหมดของคุณเพื่อให้สามารถสร้างฟังก์ชั่น wrapper สำหรับนามแฝงของคุณ
               
              
bash --versionเพื่อรับสิ่งนี้ (อย่าใช้-vเอาต์พุตที่ต่างกัน)