Bash completion is a feature that allows users to quickly complete commands, file names, and other text in the Bash shell. One common customization is setting the default behavior to complete the word under the cursor as soon as you press the Tab key. In this article, we'll explain how to set the default word as the first tab in the terminal line using various methods.
Prerequisites
To follow this guide, you need to have Bash installed on your system. Most Linux distributions come with Bash pre-installed. If you're using a Mac, you can install Bash using Homebrew or another package manager.
Method 1: Setting Default Word as First Tab using .bashrc
The .bashrc file is a configuration file for Bash. You can add the following line to set the default behavior to complete the word under the cursor as soon as you press the Tab key:
# Enable tab completion for the default shell if [ -f ~/.inputrc ]; then source ~/.inputrc fiEnable word completion
shopt -s compwords
Save the file and restart your terminal session for the changes to take effect.
Method 2: Setting Default Word as First Tab using .inputrc
The .inputrc file is another configuration file for Bash that is specifically used for setting input editing options. You can add the following lines to set the default behavior to complete the word under the cursor as soon as you press the Tab key:
# Enable tab completion for the default shell set editing-mode viEnable word completion
set word-seq-file ~/.words set enable-keymap
Set the default behavior to complete the word under the cursor as soon as you press the Tab key
set tab-always-indent on set tab-stop-list "\t" set binding "\t:complete-word"
Create the .words file and add words you frequently use to speed up completion. Save the files and restart your terminal session for the changes to take effect.
Method 3: Setting Default Word as First Tab using .bash_aliases
The .bash_aliases file is a file where you can define aliases for frequently used commands. You can add the following line to set the default behavior to complete the word under the cursor as soon as you press the Tab key:
# Enable tab completion for the default shell if [ -f ~/.inputrc ]; then source ~/.inputrc fiEnable word completion
if [ -f ~/.bashrc ]; then source ~/.bashrc fi
Set the default behavior to complete the word under the cursor as soon as you press the Tab key
if [ -f ~/.inputrc ]; then source ~/.inputrc bind "\t:complete-word" fi
Save the file and restart your terminal session for the changes to take effect.
Custom Commands in Containers
If you're using containers, such as Docker or podman, and need to run custom commands that are prefixed with Nextcloud, you may need to prefix them with the container name. For example:
# Run a custom Nextcloud command
container_name my_nextcloud
docker exec -it $container_name bash -c "nextcloud some_command"
- Bash completion is a useful feature that allows users to quickly complete commands, file names, and other text in the Bash shell.
- To set the default behavior to complete the word under the cursor as soon as you press the Tab key, you can use the .bashrc, .inputrc, or .bash_aliases files.
- If you're using containers, you may need to prefix custom commands with the container name.
References: