Add a Separator & Time Stamp Between Terminal Commands to Increase Readability

Oct 3, 2011 - 21 Comments

Vulcan prompt and a divider between commands in OS X Terminal

If you want to customize the Terminals appearance a bit beyond the prompt and a custom background, you can make the Terminal much more readable by using this nice trick to add a separator and timestamp between each executed command. This also bolds the current command text and anything that is available from tab completion.


To get this to work, you just need to paste a script into your .bash_profile. Here’s how to do this, including how to make a backup of your existing bash profile in case you mess something up:

  • Open the Terminal and type ‘cd’ to make sure you are at the home directory
  • Backup your existing .bash_profile by typing:
  • cp .bash_profile .bash_profile-backup

  • Now open .bash_profile with nano (or your preferred text editor):
  • nano .bash_profile

  • Navigate to the end of .bash_profile and copy and paste the code below, depending on which you want to display:

(If you have trouble viewing the embedded code, you can see the standard version here or opt for the excellent Vulcan Spock Salute version here) The embedded code below is the standard version:

  • Now hit Control+O to save the changes, then hit Control+X to exit out of nano
  • Open a new Terminal window and start entering commands to see the separator

Remember if you want to revert this you can either delete the code from bash_profile or just go back and replace it with your backed up copy, named .bash_profile-backup and located in your home directory.

This is what the revised Paul Prompt with Vulcan Emoji looks like, you can find this on Github:

Vulcan prompt and a divider between commands in OS X Terminal

And here’s the original version covered by AJ, with a simple divider but no color ls output and no Emoji prompt:

Custom Terminal separator and timestamp for Bash

Pick whichever you prefer.

This is a pretty nice way to customize the command line a bit and make it easier to read, but it’s not nearly as dramatic as TermKit or some of the other crazier options out there.

As long as you’re using bash you should be able to do the same with other variations of unix too. This is a cool little trick that Lifehacker modified from Emilis Dambauskas, you can get a different variation for Linux at either of those sites if for some reason this one doesn’t work for you. Thanks to Marcus for sending this to us.

(Updated by Paul on 4/20/2015 to include colorized ls, Spock LLAP emoji prompt, and minor changes to overall UI – LLAP prompt requires modern version of OS X)

.

Related articles:

Posted by: AJ in Command Line, Customize, Mac OS, Tips & Tricks

21 Comments

» Comments RSS Feed

  1. Cody says:

    As a computer programmer I am both bemused and amused that people are criticising this. Here’s a reality all good programmers know:

    NEVER EVER FALL INTO THE DELUSION YOU KNOW WHAT *ALL* YOUR USERS WANT. OR ALL USERS FULL STOP.

    Do so at your own peril…and when it comes to customising it by definition involves preference. If you don’t know what that means or what the implications are you shouldn’t be giving your opinion because it’s just arrogant and ignorant. Obviously people like this or else it wouldn’t exist and be shared – but nobody is telling you to implement on your system. I’ve been using unix for well over two decades and I have mates who have used it even longer; my mother used it in the 80s if not 70s! Unix is a brilliant OS for so many reasons (the pipe: allowing creating tools/etc. that the designers of the tools didn’t ever dream of and couldn’t have done without other tools in the first place! This is also a form of customisation) and throw in FOSS and it has so many options. Except to those with are close-minded. Like some of the commentators here. That mentality stifles innovation and progression. Add arrogance – believing that only your opinion matters or is correct – and it’s even worse. Your opinion isn’t any more relevant than anyone else here – including mine. Although ironically I’ve not given an opinion on the actual topic; I’m just calling out the folly of those who are criticising – and as usual it’s criticising and not constructive criticism. Even worse is there are some borderline ad hominem comments here. What is certain though is the truth I cite above is in fact a truth. And so is the idea that close-mindedness stifles innovation and progression etc. Well and the power of the Unix pipe and pretty much everything else. My opinion on the script here doesn’t matter though because it’s actually AN OPINION.

  2. tim says:

    what is the code for JUST THE SEPARATOR?
    i have already got my .bash_profile the way i like it and just want the separator without the rest of that mess. cheers.

  3. Matt Carrell says:

    I find this script instead to be a bit more pleasant and useful:
    —————————————————————————————————————————————————————————————————————————————————————— #
    # #
    # —————————————————————————————————————————————————————————————————————————————————————— #
    # #
    # After each result, separtes entry from next command for +clarity in bash history logging #
    # by filling the width of separation lines with chosen symbols and a time stamp at the end #
    # plus it stylizes the command prompt as well before exiting to take the next user command #
    # —————————————————————————————- #
    # (The width of windows and lines are recalculated each time for function prompt_command.) #
    # —————————————————————————————- #
    # #
    # >History: #
    # #
    # Modified from emilis bash prompt script found at: #
    # https://github.com/emilis/emilis-config/blob/master/.bash_ps1 #
    # #
    # Modified for use with the elegance that is Mac OS X Terminal by @corndogcomputer #
    # #
    # Further redundancy scrubbed, compacted, refined & enhanced by MattCarrell of NoNameSolar #
    # #
    ##############################################################################################

    # Improve ls command directory listings by changing some default switches…
    # Add a “G” to the other switch characters after “alias ls=’ls -” for multi-color directory listings.

    alias ls=’ls -fhFs’

    # Setup variables with styles and colors for faster / easier tweaking of this script…
    # Style and Color KEY: [S;C#m\] .. where Style (S) is 0 = Normal, 1 = Bold, 2 = Faint
    # …. and Color (C#) is ANSI color 30-37 (normal 1-8) or 90-97 (BRIGHT colors 1-8)
    # …. and color [0;39m\] is Text Color setting and [1;39m\] is Bold Text Color
    # * Note: The actual color for any given color number is set in Terminal preferences.
    line_symbol=”–” # The wider en-dash or f-dash character (alt + minus key) makes an unbroken line.
    reset=’\[33[0;30m\]’ # Base command Escape sequence.
    line_style=$reset’\[33[2;30m\]’ # Style;Color# of separater line.
    time_style=$reset’\[33[0;39m\]’ # Style;Color# of the time stamp.
    status_style=$reset’\[33[0;39m\]’ # Style;Color# of the status/working path info.
    ready_prompt=”»” # Separtes stats/working path info from next user command input. The » char is shft+alt+\.
    command_style=$reset’\[33[1;39m\]’ # Style;Color# of the user input.

    # Setup composition and style of user terminal ready command prompt:

    PS1=”$line_style”‘$line'”$time_style”‘\t\n'”$status_style”‘${debian_chroot:+($debian_chroot)}\u:\w'”$ready_prompt””$command_style”

    # Reset color for command output (invoked every time before a command is executed):

    trap ‘echo -ne “33[00m”‘ DEBUG

    function prompt_command
    {
    # create a $line_size of all screen width minus the time string and a space:

    let line_size=${COLUMNS}-9
    line=””
    while [ “$line_size” -gt “0” ]
    do
    line=”$line_symbol””${line}” # fill with chosen symbol
    let line_size=${line_size}-1
    done

    # If this is an X_Terminal set the title to user@host:dir

    case “$TERM” in xterm*|rxvt*)
    bname=`basename “${PWD/$HOME/~}”`
    echo -ne “33]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}07”
    ;;
    *)
    ;;
    esac
    }

    PROMPT_COMMAND=prompt_command

  4. that dude says:

    This is horrible. There is too much fluff in this. All that was explained was a separator and a time stamp. Which I could write in a few lines.

  5. jose says:

    nifty. but do not want the full PWD printed out…how can we leave it how it was and just add the timestamp?

    thanks

  6. Tom S says:

    Works great and is incredibly useful for admin tasks on my MacBookPro 10.6.8 Does not work for 10.5.8. Could you post a modified version? Would this work in Lion / Mountain Lion?

  7. Nuk says:

    Hmm, I like it but I’d rather not have the fontface in bold. How do I change it to regular?

    Also, my terminal screen is deep blue, how can I have the separator bar in white?

    TIA

  8. Chris says:

    Nice overview. Horrible PS1. Glad you like it… Been doing unix for 15 yrs. Like it minimal… Username and pwd … Drop that godawful separator!

    Aloha!

  9. Apprentice says:

    OSXDaily is a good web site that I have learned much from it. For this subject, I would like to contribute a little with my personal setting. You can see my setting here:

    http://lion.ee.ntu.edu.tw/~hylin/term.html

    Try it and see if you like it.

  10. sparky says:

    inefficient fill routine. try:

    fill=$(/usr/bin/jot -s \- -b \- $fillsize)

    instead of that while/do loop.

  11. robbedoes says:

    file was created but nothing happens

  12. robbedoes says:

    I get an error:

    cp: .bash_profile: No such file or directory

  13. Bink of Boldhome says:

    Seriously? This is a superb reason that most Mac users should never be permitted to run Terminal.app or X11. Stay away from the keyboard and stick what you know: your MOUSE.

    • sparky says:

      surely you don’t speak for everyone when you proclaim, “don’t dare learn anything new! get back to your bucket of lard, slackers!”

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site