Skip to content

Instantly share code, notes, and snippets.

@atuleu
Last active January 6, 2016 14:26
Show Gist options
  • Save atuleu/90a870e43399ea9cd6d2 to your computer and use it in GitHub Desktop.
Save atuleu/90a870e43399ea9cd6d2 to your computer and use it in GitHub Desktop.
Funny prompt with zodiac sign
# This is a funny prompt that would display the zodiac sign corresponding to the date of creation (date when the file is sourced)
# computes the right UTF-8 zodiac sign from today's date
function __today_zodiac
{
local today=$(date +%m%d)
if [ $today -le 0120 ]
then
sign=$'\u2651' # "capricorn"
elif [ $today -le 0219 ]
then
sign=$'\u2652' # "aquarius"
elif [ $today -le 0320 ]
then
sign=$'\u2653' # "pisces"
elif [ $today -le 0420 ]
then
sign=$'\u2648' # "aries"
elif [ $today -le 0521 ]
then
sign=$'\u2649' # "taurus"
elif [ $today -le 0621 ]
then
sign=$'\u264a' # "gemini"
elif [ $today -le 0722 ]
then
sign=$'\u264b' # "cancer"
elif [ $today -le 0822 ]
then
sign=$'\u264c' # "leo"
elif [ $today -le 0923 ]
then
sign=$'\u264d' # "virgo"
elif [ $today -le 1023 ]
then
sign=$'\u264e' # "libra"
elif [ $today -le 1122 ]
then
sign=$'\u264f' # "scorpio"
elif [ $today -le 1221 ]
then
sign=$'\u2650' # "sagittarius"
else
sign=$'\u2651' # "capricorn"
fi
eval "$1='$sign'"
}
# saves the today's zodiac in a variable
sign_of_birth=""
__today_zodiac sign_of_birth
# now we define the prompt in a command
function __prompt_command
{
#we would like to display the last return code
local EXIT="$?"
local reset="\[\033[0m\]"
local green="\[\033[32m\]"
local bold="\[\033[1m\]"
local cyan="\[\033[36m\]"
local yellow="\[\033[33m\]"
local red="\[\033[31m\]"
local check_mark=$'\u2713'
local ballot_x=$'\u2717'
PS1=""
if [ $EXIT != 0 ]
then
PS1+="$red$ballot_x$reset ($EXIT)"
else
PS1+="$green$check_mark$reset"
fi
# optionally one would like to call __today_zodiac to update the sign for each command. Kind of overkill
# __today_zodiac sign_of_birth
# the rest is a usual prompt displaying, here with __git_ps1
PS1+=" \d|$bold\@$reset $yellow\w\n$green$bold\u$reset@$cyan\h$reset$red\$( __git_ps1 '(%s)')$reset $bold$sign_of_birth$reset "
}
#simply sets the prompt to use a prompt command
export PROMPT_COMMAND=__prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment