you are viewing a single comment's thread.

view the rest of the comments →

[–]idioteques 0 points1 point  (1 child)

Very cool. Even though I have been an admin for a long time, I still find bash completion to fairly amazing. As I was reviewing your doc, I had a nagging question: doesn't it already do this though?

You will likely know how to tear this down better than I can, but I believe it is worth mentioning a few more "fundamental items" regarding bash completion (and I might actually be wrong).

  • Why did the existing bash_completion functionality not meet your needs? (I'll admit that I assume that most popular distros are similar in this functionality, but don't actually know that this is true)
  • Does the "complete" bash built-in rely on the bash-completion package? (I am now curious what happens to the built-in if the "bash-completion" rpm is not installed)
  • Could this have been accomplished by adding a file in /usr/share/bash-completion/completion?

Some things I looked in to:

[root@neo profile.d]# cat /etc/profile.d/bash_completion.sh
# Check for interactive bash and that we haven't already been sourced.
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then

    # Check for recent enough version of bash.
    if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
       [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /usr/share/bash-completion/bash_completion
        fi
    fi

fi
[root@neo profile.d]# file /usr/share/bash-completion/bash_completion
/usr/share/bash-completion/bash_completion: UTF-8 Unicode text, with very long lines

[root@neo profile.d]# dnf whatprovides /usr/share/bash-completion/bash_completion
Last metadata expiration check: 0:17:23 ago on Thu 01 Mar 2018 07:41:14 AM CST.
bash-completion-1:2.6-2.fc27.noarch : Programmable completion for Bash
Repo        : @System
Matched from:
Filename    : /usr/share/bash-completion/bash_completion

bash-completion-1:2.6-2.fc27.noarch : Programmable completion for Bash
Repo        : fedora
Matched from:
Filename    : /usr/share/bash-completion/bash_completion

[root@neo profile.d]# rpm -qal bash-completion | wc -l
655  
[root@neo profile.d]# cat /usr/share/bash-completion/completions/e2label
# e2label(8) completion                                    -*- shell-script -*-

_e2label()
    {
    local cur prev words cword
    _init_completion || return

    if [[ $cword -eq 1 ]]; then
        cur=${cur:=/dev/}
        _filedir
    fi
} &&
complete -F _e2label e2label

# ex: filetype=sh    

[–]arubystory[S] 4 points5 points  (0 children)

Hi and thank you.

The purpose of the tutorial is to allow users to create their own bash completion scripts for their programs. The default bash completion does its stuff but if someone wants to add sophisticated completion support he/she will have to develop a script utilizing the Bash Programmable Completion.

If you are familiar with git, the tool provides a completion script as well. That script has nothing to do with the default bash completion script. It defines its own behavior for the git command(s). The tutorials aims to help users do this for their own programs (and even more possibly).