/custom-bash

Customize your shell on startup

Primary LanguageShell

Customize Bash

Overview

Environment: UNIX/Linux

For macOS users, check out this guide: Deck Out Your Mac Terminal: Part I

In order to customize your shell with aliases, colors, and set a custom prompt, start by adding a .bashrc and a .bash_profile file.

The .bash_profile is executed for login shells and the .bashrc is executed for interactive non-login shells. When you login using a username and password to a server/virtual machine (vm) via ssh or directly on a machine, the .bash_profile is executed to configure the shell before the initial command prompt appears. If you have already logged into the server/vm and open a new terminal window, then the .bashrc is executed before the command prompt appears. The .bashrc is also run when you switch back from another shell (i.e ksh or zsh) into bash.

Steps

  1. On your server / VM, set bash to be your permanent login shell
# set bash as login shell 
chsh -s $(which bash)

# check if your shell changed
cat /etc/passwd | grep $(whoami)
  1. Clone the two files and place them into your user home directory
# go into user home
cd ~

# clone repo
git clone https://github.com/zarinlo/custom-bash.git
  1. Customize your .bashrc by adding other aliases or changing up the PS1 (Prompt String 1)

  2. Change permissions on the two files and source the .bash_profile

# make files executable 
chmod u+x .bashrc
chmod u+x .bash_profile 

# execute to configure your shell 
source .bash_profile
  1. Exit the shell and log back in to see the changes take affect

  2. If you kept the default .bashrc provided, you should have the following prompt:

PS1

References