Ivan Zyranau
Ivan Zyranau

Reputation: 941

Zsh don't wait for prompt

I have some prompt set in oh-my-zsh theme which include some 'curl/wget' commands which obtain weather status. But every time I start the shell, prompt just waiting like 9-10 seconds before welcome me. What I'd like to do is to be able to set 'dynamic' prompt: default prompt without weather shows up momentarily when I start shell, then in 'background' weather is obtained and added to prompt (for example, when some command was executed and another one prompt shown). How can I do that?

UPDATE: I decided to go with cron job which will fetch weather simply every 5 minutes and then I can cat it not only to zsh prompt, but to any system part I want (for example, to WM statusbar). Although for people who are looking for answer on my exact question I'd recommend to try something like James Andrews proposed.

Upvotes: 0

Views: 450

Answers (2)

Jon
Jon

Reputation: 2123

In your .zshrc file you could set

# How long to wait before calling TRAPALRM()
TMOUT=300

# called when TMOUT reaches 0
TRAPALRM()
{
    # run this command in the background so my shell resets
    {
        export WEATHER=$(...)
    }&!
}

And your prompt could use the $WEATHER variable.

Upvotes: 2

glenn jackman
glenn jackman

Reputation: 246837

Couple of ideas:

  1. use the curl --max-time option to limit the damage.
  2. have a cron job that runs every 5 minutes or so, fetch and write the weather to a file, your prompt can read the file.

Upvotes: 0

Related Questions