Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: trick: up-to-the-minute time in prompt
- X-seq: zsh-users 12044
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: trick: up-to-the-minute time in prompt
- Date: Thu, 18 Oct 2007 06:38:49 -0700
- In-reply-to: <20071018114641.12315.qmail@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20071018114641.12315.qmail@xxxxxxxxxxx>
On Oct 19, 12:46am, Atom Smasher wrote:
}
} here's a neat trick i just figured out... have the time that's displayed
} in your prompt update itself!
Yep; I've been having TRAPALRM update a clock in my xterm title for ages.
The reset-prompt function is recent, and necessary to get the prompt to
change, which is why I used the title bar.
Here's what I have:
# Update title bar periodically if it has been idle a long time (10 min).
# Otherwise let precmd() do it, so we don't cause unwanted scroll-to-bot.
TRAPALRM() { TMOUT=60 ; title }
precmd() { TMOUT=600 ; title }
I have xterm set for "scroll to bottom on tty output" so I don't want
the time/title updated between commands in case I'm paging through the
scrollback buffer.
The "title" function does a print -nP with terminal-specific titlebar
escapes. I've been thinking about changing it to fiddle with the
prompt if the version of zsh supports reset-prompt, but I kind of like
having the time of each terminal show up in my icon panel.
} ## this PS1 will use the `uptime` command to display system stats,
} ## updated every $TMOUT seconds
} ## example of prompt command substitution
} setopt PROMPT_SUBST
} PS1='%S$(uptime)
} %#%s '
Might I suggest:
TRAPALRM () { psvar[1]="$(uptime)"; zle reset-prompt }
PS1=$'%S%1v\n%#%s '
TMOUT=30
Then you don't need PROMPT_SUBST.
You could also do
TRAPALRM () {
psvar=(${(s:,:)$(uptime)})
psvar[1,2]=(${${=psvar[1]}[1]} "${${=psvar[1]}[2,-1]}, ${psvar[2]}")
psvar[4,-1]=("${(j:,:)psvar[4,-1]}")
zle reset-prompt
}
and then you have the clock in %1v, the uptime in %2v, the number of
users in %3v, and load average in %4v and you can do stuff like:
PS1=$'%S%2v,%4v\n%#%s '
RPS1="%B%1v%b"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author