Weblog entry #1 for toryoni
#1
Software Engineer, Linux Admin
Posted by toryoni on Mon 9 Mar 2009 at 05:16
I was inspired by Dave Vehrs after I downloaded his custom prompt script and looking around for a proper DOW.sh to include in it, after I could not find it, I wrote one ! what you see here is a script that may be executed at a console prompt. a caveat: I read many help sites about various implementations of a DOW.sh, with this one it should help quite a few people out there that are having problems with it.
#!/bin/bash
# Filename: DOW.sh
# Written 09 March, 2009 by Paul D. Thompson
#
RS='\033[0m'
HIGH='\033[1m' # Hicolor attribute
BOLD='\003[6m'
BLINK='\033[5m' # Blinking attribute
INVERSE='\033[7m' # Invert background and foreground
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LGRAY='\033[0;37m'
GRAY='\033[1;30m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LBLUE='\033[1;34m'
PINK='\033[1;35m'
LCYAN='\033[1;36m'
WHITE='\033[1;37m'
function WhatDayIsIt()
{
export DAY=`date +%A`
case $DAY in
Monday ) DayColor="$LGREEN" ;; # This is the first day of the week on my system e.g. 1
Tueday ) DayColor="$YELLOW" ;; # 2 ... exporting DAY='date +%u would probably be more
Wednesday ) DayColor="${LRED}$BLINK" ;; # 3 ... expedient because this would be using #'s instead
Thursday ) DayColor="$PURPLE" ;; # 4 ... of the actual word name for the day of the week,
Friday ) DayColor="$PINK" ;; # 5 ... but for readability, I used the date +%A format.
Saturday ) DayColor="$LCYAN" ;; # 6
Sunday ) DayColor="${CYAN}" ;; # 7
esac
echo -ne "${DayColor}$(date '+%A, %d %B %Y') @ $(date '+%H%M') Hours $(date +%Z%n)${RS}\[\n\]"
}
WhatDayIsIt
#!/bin/bash
# Filename: DOW.sh
# Written 09 March, 2009 by Paul D. Thompson
#
RS='\033[0m'
HIGH='\033[1m' # Hicolor attribute
BOLD='\003[6m'
BLINK='\033[5m' # Blinking attribute
INVERSE='\033[7m' # Invert background and foreground
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LGRAY='\033[0;37m'
GRAY='\033[1;30m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LBLUE='\033[1;34m'
PINK='\033[1;35m'
LCYAN='\033[1;36m'
WHITE='\033[1;37m'
function WhatDayIsIt()
{
export DAY=`date +%A`
case $DAY in
Monday ) DayColor="$LGREEN" ;; # This is the first day of the week on my system e.g. 1
Tueday ) DayColor="$YELLOW" ;; # 2 ... exporting DAY='date +%u would probably be more
Wednesday ) DayColor="${LRED}$BLINK" ;; # 3 ... expedient because this would be using #'s instead
Thursday ) DayColor="$PURPLE" ;; # 4 ... of the actual word name for the day of the week,
Friday ) DayColor="$PINK" ;; # 5 ... but for readability, I used the date +%A format.
Saturday ) DayColor="$LCYAN" ;; # 6
Sunday ) DayColor="${CYAN}" ;; # 7
esac
echo -ne "${DayColor}$(date '+%A, %d %B %Y') @ $(date '+%H%M') Hours $(date +%Z%n)${RS}\[\n\]"
}
WhatDayIsIt
Comments on this Entry
Please note that this is OK if you want to print it. It's bad if you want to use it inside the prompt. After the shell prints the prompt, it needs to know how many characters it has just printed, which is impossible if you mix printable chars and control sequences without using the \[ and \] constructs.
[ Parent | Reply to this comment ]
Posted by Anonymous (92.233.xx.xx) on Thu 19 Mar 2009 at 14:27
This made me laugh a bit. All that scripting to colourfully inform someone of the day of the week! And the colours don't even work on some shells... Heh.
Not to mention the fact there's an inbuilt calendar.
Not to mention the fact there's an inbuilt calendar.
[ Parent | Reply to this comment ]