Return to Level1Techs.com

BASH prompt ideas

#1

So, when running FreeBSD, i used csh, and used a prompt that began with : and ended with ; so that i could copy/paste commands by just highlighting entire lines and the prompt was commented out.

I’ve been messing with my prompt in bash (used to always just with [email protected]:/dir).

I think I’ve settled on (for now):

PS1="# \t - \[email protected]\h:\w\n\n"

Which gives me something like this

# 10:26:29 - [email protected]:~

ls
Desktop    Downloads  Pictures  source     Videos
Documents  Music      Public    Templates  VMware
# 10:26:32 - [email protected]:~

I like this for the following reasons:

  • I have a datestamp on any commands i ran, so i can do retroactive post mortem if i fuck things up.
  • i can copy/paste entire previous commands without needing to extract the prompt. If there are a series of commands with no output displayed, i can just highlight many lines and the prompt is hashed out and will do nothing.
  • the extra new-line, whilst taking up vertical space makes it very clear where a command-line begins and ends.

Anyone have any other nifty prompt tricks?

edit:
i might add colour, but that’s just going to be for further clarity… with csh i set up root’s prompt to be RED instead of blue or white so it was abundantly clear you were logged in as a potentially destructive user.

Might also add the date. I definitely think i prefer having the prompt with relevant info on its own line…

2 Likes

#2

Updated it to this:

PS1="# \D{%Y-%m-%d}T\t+08 - \e[31m\u\e[[email protected]\h:\e[34m\w\e[0m\n\n"

Which gives me a colourised prompt as per:

# 2019-05-13T14:34:12+08 - [email protected]:~

… with an ISO8601 date-stamp :slight_smile:

0 Likes

#3

http://bashrcgenerator.com/ is a good site to play around with for creating customised bash prompts.

2 Likes

#4

My prompt changes colors based on OS, a red ‘X’ if the last command was an error and shows git related info:

[email protected]:~/RCFiles [Mon May 13] (master) X
>

The relevant part of my ~/.bashrc:

1 Like