2 minute read Published:

ZSH: Emoji Analog Clock

Just about any example of a of customized ZSH prompt that you’ll find on the internet has time shown.

PROMPT='time: %T > '

I can’t recall the last time I noticed or gained any advantage of having the time printed in the terminal.

Lots of other customized ZSH prompts also have some emoji characters to spice things up. Skulls 💀, ghost 👻, etc. That’s easy enough to add.

ghost=$'\U1F47B'
PROMPT='time: %T $ghost >

Screenshot from 2018-06-30 15-04-03

You can also directly paste an emoji into your configuration file, but I didn’t like the idea of having none regular text in my configuration files. Also, I’d like to make the emoji on my prompt a little more dynamic. And this is where the discussion of putting time into your custom prompt comes back.

The full set of o’clock emojis are defined between 0x1F550 to 0x1F567 and looks like this.

Screenshot from 2018-06-30 15-25-58

It first defines top of the hour from 1 to 12 then the half hours from 1 to 12. So with a little bit of script we can get the command line to show us an analog clock of the current time by simple getting the hour and increment from the first hex value.

current_clock_emoji() {
    hour=$(date +"%l")
    echo -n '\U'$(([##16] 0x1F550 + hour - 1))
}

A couple of note about this code: The %l gets the hour from 1-12 without padding, the #16 tells ZSH that you want to do hexadecimal arithmetic, and the extra pound(#) symbol says to not output the base prefix (ZSH arithmetic).

Now call the method when setting up your prompt. Pretty straight forward.

PROMPT='time: %T $(current_clock_emoji) > '

Here is what my final prompt looks like.

Screenshot from 2018-06-30 15-39-05

I didn’t bother changing the clock for every half hour because that sort of granularity probably won’t be helpful. Here is a solution that changes the emoji on the quarter hours.

Extra

Below is the code I used to print out all the clocks.

display_clocks(){
    for i in `seq 0 $((0x1F567 - 0x1F550))`; do
        echo -n ' \U'$(([##16] 0x1F550 + $i))
    done
}