How to enable bash command autocomplete on Alpine Linux

Bash autocompletion is a feature that provides tab completion of command arguments, commands, and much more, Bash is a sh-compatible command language interpreter that runs commands read from the keyboard or a file. Bash-completion/autocompletion is a collection of shell functions that take advantage of the programmable completion feature of Bash on Alpine Linux. This page shows how to install and enable Bash autocomplete auto-completion in Alpine Linux.

Let us see how to install and enable bash command autocomplete to increase productivity.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Alpine Linux
Est. reading time 3 mintues

Enabling bash command autocomplete on Aline Linux

The procedure is as follows to add bash completion support in Alpine:

  1. Open the terminal application.
  2. For remote server log in using the ssh command and then type: apk update
  3. Install bash-completion package on Alpine Linux by running the apk command: apk add bash-completion
    How to install bash command autocomplete on Alpine Linux

    Installing bash-completion

  4. Use the source command to load autocompletion: source /etc/profile.d/
  5. Edit the ~/.bash_profile and append the line: source /etc/profile.d/
  6. Set up bash as a default shell by editing the /etc/passwd. For example, vivek:x:500:500:Vivek Gite:/home/vivek:/bin/bash
  7. Log out and log in to verify that bash auto completion in Alpine Linux is working as configured and installed.

Bash auto completion related files

All newly installed shells are listed in the /etc/shells file. When you edit the /etc/passwd to change the shell to bash, use the correct path mentioned in /etc/shells. So type the following grep command/cat command:
cat /etc/shells
grep bash /etc/shells

It is important that you find bash shell version to solve any scripting problem. Hence, run the following command to see GNU/bash version:
bash --version
See “how to find out what shell I am using on Linux/Unix” for more details.

Related: How to install bash shell in Alpine Linux

Find out where Alpine Linux stores bash autocomplete

Want to learn how bash command autocomplete works? Run the following commands:
cat /etc/profile.d/

# shellcheck shell=sh disable=SC1091,SC2039,SC2166
# Check for interactive bash and that we haven't already been sourced.
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BASH_COMPLETION_VERSINFO-}" = x ]; then
    # Check for recent enough version of bash.
    if [ "${BASH_VERSINFO[0]}" -gt 4 ] ||
        [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 2 ]; 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

Now, cd into the /usr/share/bash-completion/completions/ and see files:
cd /usr/share/bash-completion/completions/
ls -l

See auto completion for man command:
vi man
cat man

Sample ~/.bash_profile for bash autocompletion

Display using the cat command:
cat ~/.bash_profile

source /etc/profile.d/
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='\u@\h:\W \$ '
alias vi='vim'
alias vnstat='vnstat -i eth0'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "

Installing ZFS bash auto completion support

By default, the zfs support not installed for the Alpine Linux server. Therefore we need to add it. First, grab the file using wget command or curl command to download file from OpenZFS project repo:
mkdir ~/bash_completion/
cd ~/bash_completion/

Verify file using a text editor such as vim command:
vim zfs
Edit the ~/.bash_profile and append the following line to load zfs support:
source ~/bash_completion/zfs


You learned how install and enable bash command autocomplete under Alpine Linux. Bash-completion is a collection of command-line command completions for the Bash shell, a group of helper functions to create new completions, and a set of facilities for loading completions automatically on-demand, as well as installing them. Hence, see project home page to view documentations and source code for learning purposes.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum