DEV Community

Hilton Meyer
Hilton Meyer

Posted on • Originally published at hiltonmeyer.com on

1

Custom Bash Command Prompt

This is the setup I use for my bash prompts in various environments. I simply add the following to my .bashrc file. This is more a reference for me but if you find it useful give it a go and play around with the various colors.

Custom Prompt###############
set_prompt () {
        Reset='\[\e[0m\]'

    Black='\[\e[0;30m\]'
    Blue='\[\e[0;34m\]'
    Green='\[\e[0;32m\]'
    Cyan='\[\e[0;36m\]'
    Red='\[\e[0;31m\]'
    Purple='\[\e[0;35m\]'
    Brown='\[\e[0;33m\]'

    if [$(whoami) == 'root'] || [[$(whoami) == *"prod"*]] || [[$(whoami) == *"PROD"*]]; then
        PrimaryColor="${Red}"
        SecondaryColor="${Brown}"
        promptSymbol="${Red}!! "
    else
        PrimaryColor="${Green}"
        SecondaryColor="${Blue}"
        promptSymbol="${Green}$ "
    fi

        userhost="${PrimaryColor}$(whoami)@$(hostname -s) "
        currentdir="${SecondaryColor}[$(pwd | sed "s!^$HOME!~!")] "
    currentTime="${PrimaryColor}$(date +%H:%M:%S) "

    PS1="$Reset$White"
    PS1+="$userhost"
    PS1+="$currentdir"
    PS1+="$currentTime"
    PS1+="$promptSymbol"
    PS1+="$Reset"
}

PROMPT_COMMAND='set_prompt'
################Custom Prompt End###############

Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay