simfish:

Minimal Shell Configuration

A bare minimum Bash Shell configuration

cover image

Install

This configuration depends on the following packages:

(specifications->manifest
 '( "bash"

    ;; core
    "coreutils"
    "util-linux"
    "tree"
    "which"
    "htop"

    ;; history
    "hstr"


    ;; text based UI programming
    "ncurses"

    ;; networking
    "iputils"
    "gnutls"
    "openssl"

    ;; text processing
    "jq"
    "grep"
    "pdfgrep"
    "sed"

    ;; file & directory search
    "findutils"
    "the-silver-searcher"))

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:

/path/to/current/directory/user@$

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 dc_curr_git_branch( ) {
   # Returns the current git branch name.
   # If the current directory is not a repo, then return an empty string
    local _branch=$(git branch --show-current 2> /dev/null)
    echo "${_branch}"

    return 0
}

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

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 printf can be used. See, clear a terminal for real 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 why Bash supports two different commands to configure the shell has to do with history of the evolution of theshell 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

Emacs Integration

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

case $SHELL in
    ,*/bash)
        shopt -s direxpand
        ;;
    ,*)
        # nothing to do
esac

For example,

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