Clock Prompt

This prompt uses ANSI position codes to put a clock in the upper right corner of your term. The ANSI codes used aren't honoured by all terminal emulators, but are supported by the Linux console and xterm.

Code:


#!/bin/bash

# $Author: giles $, $Date: 1998/12/23 05:16:22 $
# $Source: /home/giles/.bashprompt/bashthemes/RCS/clock,v $, 
# $Revision: 0.18 $

function prompt_command {
let prompt_x=$COLUMNS-5
}

PROMPT_COMMAND=prompt_command

function clock {
local       BLUE="\[\033[0;34m\]"
local        RED="\[\033[0;31m\]"
local  LIGHT_RED="\[\033[1;31m\]"
local      WHITE="\[\033[1;37m\]"
local  NO_COLOUR="\[\033[0m\]"
case $TERM in
    xterm*)
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'
        ;;
    *)
        TITLEBAR=""
        ;;
esac

PS1="${TITLEBAR}\
\[\033[s\033[1;\$(echo -n \${prompt_x})H\]\
$BLUE[$LIGHT_RED\$(date +%H%M)$BLUE]\[\033[u\033[1A\]
$BLUE[$LIGHT_RED\u@\h:\w$BLUE]\
$WHITE\$$NO_COLOUR "
PS2='> '
PS4='+ '
}


https://gilesorr.org/bashprompt/prompts/clock.html 
by giles