Posts: 1,308
BitJam
Joined: 31 Aug 2009
#1
When I'm working on the command line I find that colorful and informative prompts make me more productive. I know who I am, what time it is, what system I'm on, and what directory I'm in. I can also easily spot where my previous commands were in the scrollback buffer. I like to use multi-line prompts so they can be informative yet the cursor starts very close to the left edge of the terminal.

I've created a little script called fancy-prompts that gives you easy access to seven different prompts. Each prompt has a limited amount of customization available. If you"source" the script:

Code: Select all

$ source ./fancy-prompts
[demo@antiX]-[04:13:39 PM]-------------------------------------[/usr/local/bin]
then the fancy prompts will be added to your current shell. If, instead, you run the script as a program, it creates a new Bash shell that has access to the fancy prompts:

Code: Select all

$ ./fancy-prompts
============================================================================
Starting a new bash shell.  You can avoid this by sourcing this file
instead of running it as a command.  For example:

    $ source ./fancy-prompts

You can return to your previous shell by typing"exit" or hitting <ctrl-d>
use -q (--quiet) to supress this message.  Use -h (--help) to display help.

Type"prompt-usage" to get instructions on using fancy-prompts.
============================================================================

[demo@antiX]-[04:13:39 PM]-------------------------------------[/usr/local/bin]
$ 
Here is the usage:

Code: Select all

$ ./fancy-prompts -h
There are seven fancy prompt commands available:

      prompt-tiny          prompt-narrow    
      prompt-std           prompt-med       
      prompt-color         prompt-wide      
      prompt-gentoo

Each command changes your prompt ranging from prompt-tiny, which gives you
a very simple prompt, to prompt-wide which gives you a very fancy one.
They all have these options:

    -d|--dark               Make all colors darker
    -h|--help               Display this help
    -l|--lines    <INTEGER> The number of extra new lines before the prompt
    -n|--nocolor            Turn off colors
    -p|--prompt   <STRING>  The final charter(s) displayed in the prompt

Examples:

    Use prompt-med with no extra newline and a">" final prompt character:
        prompt-med -n 0 -p">"

    Use a simple prompt containing the hostname:
        prompt-tiny -p"\h >"

Note: The username and the final prompt characters are red for the root user.
If you want a fancy prompt to be your default, just source the fancy-prompts script from your .bashrc and then set the prompt to what you want. For example:

Code: Select all

 source /usr/local/bin/fancy-prompts
prompt-wide --prompt">" --dark
DO NOT call fancy-prompts as a program from within your bashrc.

I've attached a gzipped copy of the fancy-prompts script. I hope this encourages people to use a more productive prompt for the command line and maybe it will even inspire a few people to make their own further customizations.
Posts: 1,062
Dave
Joined: 20 Jan 2010
#2
Thanks for sharing BitJam, this is a great script you made up. Will need to spend some more time looking at how it is constructed