Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Tiny problem with a prompt



On 30 July 2011 14:57, Tomasz Moskal <ramshackle.industries@xxxxxxxxx> wrote:
> 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.

You need to update PS1 inside precmd(), or use promptsubst and protect
the parameter expansion.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author