7 ms·
If you like to have the Unix epoch in your prompt, you can do something like this: function prompt_epoch() { printf -v COMMA_EPOCH "%'d" ${EPOCHSEC
by bloopernova 3y ago
If you like to have the Unix epoch in your prompt, you can do something like this:
function prompt_epoch() {
printf -v COMMA_EPOCH "%'d" ${EPOCHSECONDS}
p10k segment -f 66 -t ${COMMA_EPOCH}
}
EPOCHSECONDS relies on `zmodload zsh/datetime`. printf -v creates a variable rather than output text. p10k segment is just a function that powerlevel10k uses, you don't have to use it. COMMA_EPOCH is just the current Unix time separated by commas every 3 digits.
If you wanted your own countdown, you could easily do `2147483647 - EPOCHSECONDS` and display that time instead.
EDIT: and if you want to mimic that oh-so-cool clock, you could do:
printf '%x\n' $EPOCHSECONDS
or assign that to a variable with printf -v, then split the string into pairs. Mimicking the colours of the clock would be fairly trivial too.
- codetrotter 3y ago> EPOCHSECONDS relies on `zmodload zsh/datetime` Is there any advantage to using that module instead of invoking date +%s I use zsh but I don’t have any addons installed or anything. So for me it is less work to call date +%s instead
- bloopernova 3y agoYes, it doesn't fork a separate process. I doubt I could really tell the difference in prompt responsiveness, but I liked learning about the printf -v COMMA_EPOCH method.