Skip to content

Instantly share code, notes, and snippets.

@markcaudill
Created April 27, 2011 17:44
Show Gist options
  • Save markcaudill/944768 to your computer and use it in GitHub Desktop.
Save markcaudill/944768 to your computer and use it in GitHub Desktop.
Some code that can be used to have your timestamp in your Bash prompt be a stardate.
function stardate()
{
# There's apparently no cannon way to calculate the startdate
# but here goes.
# Add up all the minutes so far in the day, divide by minutes in 24 hours and format it nicely.
DECIMAL=$(echo $(( $(date -u '+%H') * 60 + $(date -u '+%M') )) | awk '{printf("%.2f", $1/1440)}' | sed 's/^0*//')
# Get the number of days since epoch.
DATE=$(( $(date -u '+%s') / 60 / 60 / 24 ))
echo "$DATE$DECIMAL"
}
# This prompt includes the stardate, user@hostname and the current working directory.
export PS1="[\$(stardate)][\u@\h \w]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment