Reply to message «Tiny problem with a prompt»,
sent 16:57:06 31 July 2011, Sunday
by Tomasz Moskal:
Define a `chpwd' function and call your one there. `chpwd' is called whenever
directory changes, `premcmd' is called just before prompt is shown and thus it
will reinitialize prompt too much times. Search `man zshmisc' for /Hook/ to get
more useful hook functions.
Original message:
> I am trying to display current directory in different colour based on if
> it's writeable or not. What I thought will be simple if...then...else
> task has become a really headache. My (simplistic) code is as follows:
>
>
> prompt_k2_setup() {
>
> pdir() {
> if [[ -w $PWD ]]; then
> dirp='%3F%1/%3f '
> else
> dirp='%1F%1/%1f '
> fi
> }
>
> precmd() { pdir }
>
> PS1="${dirp} "
> }
>
> prompt_k2_setup "$@"
>
>
> It sort off works, but not as I intended it to - for the prompt to show
> current directory I need to execute 'prompt k2' each time I change to
> different directory.
>
> I am probably missing something painfully obvious but I can't figure it
> out. A nudge in the right direction will be greatly appreciated.
Attachment:
signature.asc
Description: This is a digitally signed message part.