Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tiny problem with a prompt
- X-seq: zsh-users 16167
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: ramshackle.industries@xxxxxxxxx
- Subject: Re: Tiny problem with a prompt
- Date: Sat, 30 Jul 2011 15:00:54 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=bOT5BIQ8WB8FFZyo2Z0LybBSvVqaGVlk2kJsYBVKjXQ=; b=KtkM7h8E1/VKlPQ9gP7jcsR5GDjgwDRbW15fbtEpQoq7MOVttyOjqx9s57xZMOibqf 2Ewcr6bm3o9g+f6JLFk23yTDpbJ1WWjZZM6Fh90inoTDIVbyu6g8GXeur/p56a+0wdqz teX8qqzJrPlUvE9sS1jNdc9x9o2lPue2FIKxU=
- In-reply-to: <1312030627.2227.2.camel@localhost.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1312030627.2227.2.camel@localhost.localdomain>
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