Shell Configuration

Minimal Linux shell configuration settings

Shell Configuration

This is a bare minimum Bash shell configuration.

Shell Prompt

The default shell prompt can be configured using PS1 variable.

The only requirement here is the prompt string should communicates where in the file system the current user is. And when available, the name of the current git branch:


The actual configuration is straight forward. The only interesting bit is that the setting only applies to Bash. Otherwise, the prompt is left as is. This is mainly to avoid strange bleeding shell prompt bugs when using ZSH and Emacs ansi-term See for example,issue #8682.

function gc_curr_git_branch( ) {
    # Returns the current git branch name.
    # If the current directory is not a repo, then return an empty string

    local gc_working_branch=$(git branch --show-current 2> /dev/null)
    echo "${gc_working_branch}"

    return 0

case $SHELL in
        PS1='\[\e[0;38;5;243m\]${PWD}\[\e[0m\]@\[\e[0;1;35m\]$(gc_curr_git_branch)\[\e[0;91m\]\$ \[\e[0m\]'
        # nothing to do

Clear Screen

By default, Bash’s clear command does not erase the entire screen. Output from previous commands can still be observed when scrolling.

To clear the entire screen See clear terminal screen for real. can be used instead. An alias for the command can be setup as follows:

alias cls='printf "\033c"'

Bash Options

Built-in commands set and shopt are useful for toggling on and off internal Bash features. Each command supports its own set of options The reason Bash supports two different commands to configure shell options has to do with history of the evolution of the shell environment. Available shell options can be viewed as follows:

shopt    # list all options that can be accessed with shopt
set -o   # list all options that can be accessed with set

*direpand* enables tab expansion of environment variables in a file path:

shopt -s direxpand

For example,

${HOME}/Documents/[TAB] # => /home/someuser/Documents

Configuration Dependencies

Aside from customization settings, this configuration also installs the following packages:

 '( "bash"

    ;; core

    ;; history

    ;; text based UI programming

    ;; networking

    ;; text processing

    ;; file & directory search