Skip to main content
make image clickable
Source Link
Barmar
  • 10.6k
  • 1
  • 22
  • 29

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: prompt example screenshot prompt example screenshot

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: prompt example screenshot

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: prompt example screenshot

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

Became Hot Network Question
added 36 characters in body
Source Link
Stéphane Chazelas
  • 587.9k
  • 96
  • 1.1k
  • 1.7k

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: https://imgur.com/0IT5zXiprompt example screenshot

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: https://imgur.com/0IT5zXi

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: prompt example screenshot

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?

Source Link
acjca2
  • 310
  • 2
  • 8

Printf formatting a ZSH variable without forking?

For my powerlevel10k custom prompt, I currently have this function to display the seconds since the epoch, comma separated. I display it under the current time so I always have a cue to remember roughly what the current epoch time is.

function prompt_epoch() { MYEPOCH=$(/bin/date +%s | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') p10k segment -f 66 -t ${MYEPOCH} } 

My prompt looks like this: https://imgur.com/0IT5zXi

I've been told I can do this without the forked processes using these commands:

$ zmodload -F zsh/datetime p:EPOCHSECONDS $ printf "%'d" $EPOCHSECONDS 1,648,943,504 

But I'm not sure how to do that without the forking. I know to add the zmodload line in my ~/.zshrc before my powerlevel10k is sourced, but formatting ${EPOCHSECONDS} isn't something I know how to do without a fork.

If I were doing it the way I know, this is what I'd do:

function prompt_epoch() { MYEPOCH=$(printf "%'d" ${EPOCHSECONDS}) p10k segment -f 66 -t ${MYEPOCH} } 

But as far as I understand it, that's still forking a process every time the prompt is called, correct? Am I misunderstanding the advice given because I don't think I can see a way to get the latest epoch seconds without running some sort of process, which requires a fork, correct?