I just decided to try zsh (through oh-my-zsh), and am now playing with precmd
to emulate a two-line prompt that has right prompts in more than just the last line.
So I clone the default theme, and inspired by this post (that I'm using to learn a lot too), i do somehting like this (I'll add colors later):
function precmd {
local cwd="${(%):-[%~]}"
local who_where="${(%):-%n@%m}"
local git_info=${(%)$(git_prompt_info)}
local right_prompt=" $git_info [$who_where]"
local left_prompt="${(r:(($COLUMNS - ${#${right_prompt}})):: :)cwd}"
echo "$left_prompt$right_prompt"
}
And it works. But I can't help but wonder: is zsh defining all those variables every time precmd is called?
I've been googling for closures, scope and namespacing in relation to zsh, looking to attach the local vars as data to precmd, so it doesn't need to redefine the variables every time, but I have found nothing. Is there some way to do what I'm trying, or should I just drop it?
As a side note, and only if it is related, what does "to have a function loaded" mean?