You need to use the dnf command:

$ dnf search bash-completion

To get info just run the dnf command with info option:

$ dnf info bash-completion
Now all you have to do is type the following dnf command to install it:

$ sudo dnf install bash-completion

How to test programmable completion for Bash

Installer placed a script called /etc/profile.d/ You can view it with the cat command:

$ cat /etc/profile.d/

Sample outputs:

# 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

The script will get called automatically from your login session or when you start a fresh shell session. To load the current session use the source command:

$ source /etc/profile.d/

Press the [TAB] key while typing a command to auto-complete syntax or options:

sudo dnf i[TAB]

How to write simple bash completion

Ping three domain names using the ping command. So type the following at the shell prompt:

complete -W '' ping

Now type ping and press the [TAB] key to use any one of the domain names for ping command:

ping [TAB]

Let us write a simple function:

# simple script for ping command 
# Include all host names from /etc/hosts file too
_ping () {  COMPREPLY=( $(awk '{print $2}' /etc/hosts | uniq) ); }
complete -F _ping ping

Run it as follows:

ping [TAB]

How to reuse existing completions

I am going to reuse /usr/share/bash-completion/completions/lxd.lxc in my custom bash shell script wrapper:

_mylxc () {
source /usr/share/bash-completion/completions/lxd.lxc && _complete_from_snap
# note cbzlxc is my custom made wrapper and is in $HOME/bin/
complete -F _mylxc cbzlxc

Now run it as follows:

cbzlxc [TAB]

That's it !!

Was this answer helpful? 0 Users Found This Useful (0 Votes)