How To Customize Bash on Linux with Bash-it

Posted on 321 views

How can I customize my Bash on Linux?. Bash is the go-to after login to Linux system for Script-savvy users and System Administrators. By default, a Linux bash doesn’t have ostentation which keeps you engaged on the terminal for long hours. This is why you need Bash-it. Bash-it is a collection of community Bash commands and scripts for Bash 3.2+, basically, it is a shameless ripoff of oh-my-zsh.

Also check: How To Install Starship Shell Prompt for Bash / Zsh / Fish

In this article, we will burrow into customization of your Bash shell with Bash-it. This tool should be at the very top of any Bash user’s list. It helps you quickly configure a better-looking bash shell without thoroughly exploiting Bash internals.

Bash-it includes auto-completion, themes, aliases, custom functions and serves as a solid framework for using, developing and maintaining shell scripts and custom commands for your daily work.

Installing Bash-it on Linux

Installing Bash-it is a 3 seconds task. Just clone the repository from Github to ~/.bash_it directory.

git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it

You should have git installed for the command to work. See below.

# Install Git Ubuntu / Debian
sudo apt-get update
sudo apt-get -y install git

# Install Git CentOS / RHEL
sudo yum -y install git

# Install Git on Fedora
sudo dnf -y install git

# Install git on Arch / Manjaro
sudo pacman -S git

After clone is done, run installer script which automatically backs up your ~/.bash_profile or ~/.bashrc.

$ ~/.bash_it/install.sh
Would you like to keep your .bashrc and append bash-it templates at the end? [y/N] y
Your original .bashrc has been backed up to .bashrc.bak
Bash-it template has been added to your .bashrc

Enabling reasonable defaults
bash-it enabled with priority 350.
system enabled with priority 350.
base enabled with priority 250.
alias-completion enabled with priority 365.
general enabled with priority 150.

Installation finished successfully! Enjoy bash-it!
To start using it, open a new tab or 'source /jmutai/.bashrc'.

To show the available aliases/completions/plugins, type one of the following:
  bash-it show aliases
  bash-it show completions
  bash-it show plugins

To avoid issues and to keep your shell lean, please enable only features you really want to use.
Enabling everything can lead to issues.

Your original .bashrc is been backed up to .bashrc.bak and bash-it templates appended at the end of .bashrc file.

Using Bash-it on Linux

We have Bash-it installed on our Linux system, let’s activate the bash environment to update the changes.

source ~/.bashrc

Your shell should change the appearance.

customize-bash-shell-with-bash-it-1024x173

You’ll have to edit your modified config (~/.bash_profile or ~/.bashrc) file in order to customize Bash-it.

We mentioned earlier that Bash-it includes auto-completion, themes, aliases and custom functions geared towards improving your terminal productivity. Here are helpful commands you can use to reveal these configurations.

Using Bash-it Aliases

Use the command below to list all aliases:

$ bash-it show aliases

Most aliases are not enabled by default, enable them using the syntax.

$ bash-it enable alias   [alias name]
E.g.

1. Enable Aliases for Vagrant
$ bash-it enable alias vagrant
vagrant enabled with priority 150.

2. Enable Ansible Aliases
$ bash-it enable alias ansible

To enable all aliases, use:

$ bash-it enable alias all
ag enabled with priority 150.
ansible enabled with priority 150.
apt enabled with priority 150.
atom enabled with priority 150.
bolt enabled with priority 150.
bundler enabled with priority 150.
clipboard enabled with priority 150.
composer enabled with priority 150.
curl enabled with priority 150.
docker enabled with priority 150.
docker-compose enabled with priority 150.
emacs enabled with priority 150.
fuck enabled with priority 150.
general is already enabled.
git enabled with priority 150.
gitsvn enabled with priority 150.
heroku enabled with priority 150.
hg enabled with priority 150.
homebrew enabled with priority 150.
homebrew-cask enabled with priority 150.
homesick enabled with priority 150.
jitsu enabled with priority 150.
kubectl enabled with priority 150.
laravel enabled with priority 150.
maven enabled with priority 150.
msys2 enabled with priority 150.
npm enabled with priority 150.
osx enabled with priority 150.
phoenix enabled with priority 150.
puppet enabled with priority 150.
pyrocms enabled with priority 150.
rails enabled with priority 150.
svn enabled with priority 150.
systemd enabled with priority 150.
textmate enabled with priority 150.
tmux enabled with priority 150.
todo.txt-cli enabled with priority 150.
vagrant is already enabled.
vault enabled with priority 150.
vim enabled with priority 150.
yarn enabled with priority 150.
yarn enabled with priority .

To show help for aliases, run:

$ bash-it help aliases

See sample output.

....................................................
vagrant:
vhl='vagrant hosts list'
vscp='vagrant scp'
vsl='vagrant snapshot list'
vst='vagrant snapshot take'
vup="vagrant up'
vupl="vagrant up 2>&1 | tee vagrant.log'
vh="vagrant halt'
vs="vagrant suspend'
vr="vagrant resume'
vrl="vagrant reload'
vssh="vagrant ssh'
vst="vagrant status'
vp="vagrant provision'
vdstr="vagrant destroy'
vl="vagrant list'
vhst="vagrant hostmanager'

vault:
vad="vault delete'
val="vault list'
var="vault read'
varn="vault renew'
varv="vault revoke'
vasrv="vault server'
vas="vault status'
vav="vault version'
vaw="vault write'
vag="vault login -method=github'
varv="vault read -field=value'

To disable an alias, run:

$ bash-it disable alias  [alias name]…
#or
$ bash-it disable alias all

Using Bash-it completions

List all installed and available completions:

$ bash-it show completions

To enable a completion, do:

$ bash-it enable completion   [completion name]...

Example:

$ bash-it enable completion vagrant virsh pip3 openshift packer knife docker

vagrant enabled with priority 350.
virsh enabled with priority 350.
pip3 enabled with priority 350.
openshift enabled with priority 350.
packer enabled with priority 350.
knife enabled with priority 350.
docker enabled with priority 350.

Or enable all with:

$ bash-it enable completion all

To show help for installed completions, use:

$ bash-it help completions

To disable a completion, do:

$ bash-it disable completion   [completion name]...

OR

$ bash-it disable completion all

Using Bash-it Plugins

Plugins are used to extend bash features and functions. Bash-it comes with a number of plugins that you can enable to unlock them.

To list available plugins, use the command:

$ bash-it show plugins

To enable plugin, use:

$ bash-it enable plugin   [plugin name]...

OR enable all with:

$ bash-it enable plugin all

This example enables plugin used to display info about your battery charge level.

$ bash-it enable plugin battery
battery enabled with priority 250.

Then source your bashrc profile.

$ source ~/.bashrc

See output

bashit-enable-battery-plugin-1024x230

To disable a plugin, do:

$ bash-it disable plugin  [plugin name]…

-or-

$ bash-it disable plugin all

Using Search Function

Bash-it search function is used to quickly find out which of the plugins, aliases or completions are available for a specific framework, programming language, or an environment.

Use it to find stuff related to your working environment. The search syntax is:

$ bash-it search term1 [[-]term2] [[-]term3]....

Search everything related to Python:

$ bash-it search python pip
      plugins:  pipsi python
  completions:  pip pip3 pipenv

Or for Ruby developer:

$ bash-it search ruby rake gem bundle irb rails
      aliases:  bundler rails
      plugins:  chruby chruby-auto rails ruby
  completions:  bundler gem rake

The modules enabled are shown in green. You can prefix a search term with a “-” to exclude it from the results.

$ bash-it search ruby rake gem bundle irb rails -chruby

By adding a --enable or --disable to the search command, you can automatically enable all modules that come up as a result of a search query.

Changing Bash-it theme

There are over 50+ Bash-it themes to pick from in $BASH_IT/themes

$ ls ~/.bash_it/themes/

To change your Bash theme, set BASH_IT_THEME to the theme name you want to use.

$ vim ~/.bashrc

Set like below.

change-bash-theme-1024x403

You can see theme screenshots on wiki/Themes.

NOTE: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to LC_ALL=en_US.UTF-8 or the equivalent to your language if it isn’t American English.

How to Update Bash-it

To update Bash-it to the latest version, simply run:

$ bash-it update
Bash-it is up to date, nothing to do!

If you are using an older version of Bash-it, it is recommended to use migrate command.

$ bash-it migrate

This command will automatically migrate the Bash-it structure to the latest version.

How to uninstall Bash-it on Linux / Unix

To uninstall Bash-it, run the uninstall.sh script found in the $BASH_IT directory:

$ cd $BASH_IT
$ ./uninstall.sh
Your original .bashrc has been restored.

Uninstallation finished successfully! Sorry to see you go!

Final steps to complete the uninstallation:
  -> Remove the /home/jmutai/.bash_it folder
  -> Open a new shell/tab/terminal

Check the Bash-it project’s page to learn more on how to customize it. I hope this guide was helpful in your journey to a better terminal experience on Linux.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.