Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Dynamic colored command in zsh
- X-seq: zsh-users 15397
- From: Roy Zuo <roylzuo@xxxxxxxxx>
- To: Michel <michel.barret@xxxxxxxxx>
- Subject: Re: Dynamic colored command in zsh
- Date: Mon, 13 Sep 2010 21:03:45 +0800
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mail-followup-to:references:mime-version:content-type :content-disposition:in-reply-to:x-pgp-key-id:user-agent; bh=B8RXO8F8cPUXFYU6y9K5LW3yCJNpbskNyfMu97JPVkc=; b=Ky5GAfxG3lctotDjJdFC3imaLi7F4PKImRZ490MElvDymccz2XnHccUuHt5sO0Lxub buuEt6GiRWXx/0HWpxWUMTK5A5g5IprU8XyqPV2XBAPw0oxePzc57nEYChV49F8JCao5 TrXEN1+j7fsQDdQmYzpQptatvRm4ILKRuf7dI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :x-pgp-key-id:user-agent; b=xNpkLVs758Dq4VutcwBtqQz3wW1QBWy5baRTp4inWXiT7gAOQGc1sxGPFYdX7WUIbF an/4aPqSFKYkAAdGz0di1K5aolvWhAoENtzDq+SGrL44QJiVvrRwCbOAFCB9gGsNYRlG Rc7GfYBp3hdJrwmxULbIBgKTeOFeamu9w9RnM=
- In-reply-to: <AANLkTinNJXay4pibEiQmKR4PSRcNiwCJ3w==Scc9rco0@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: Michel <michel.barret@xxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <AANLkTinNJXay4pibEiQmKR4PSRcNiwCJ3w==Scc9rco0@xxxxxxxxxxxxxx>
Yes, I tried today and made some progress. I can make the color for the command
to change whenever I type a new character or delete one. However my ZLE skill is
quite limited and someone else might be able to make this also work when TAB is
pressed.
recolor-cmd() {
args=(${(z)BUFFER})
cmd=$args[1]
res=$(builtin type $cmd 2>/dev/null)
[ -z $res ] && return
if [ $res =~ 'reserved word' ]; then
color="magenta"
elif [ $res =~ 'an alias' ]; then
color="cyan"
elif [ $res =~ 'shell builtin' ]; then
color="yellow"
elif [ $res =~ 'shell function' ]; then
color='green'
elif [ $res =~ "$cmd is" ]; then
color="blue"
else
color="red"
fi
region_highlight=("0 ${#cmd} fg=${color},bold")
}
check-cmd-self-insert() { zle .self-insert && recolor-cmd }
check-cmd-backward-delete-char() { zle .backward-delete-char && recolor-cmd }
zle -N self-insert check-cmd-self-insert
zle -N backward-delete-char check-cmd-backward-delete-char
Regards,
Roy
On Sun, Sep 12, 2010 at 12:04:08PM +0200, Michel wrote:
> Hello,
>
> Is it possible to have the dynamic colored command in zsh as in fish ?
>
> By example : if I type "grep", for each caracter before the "p" the
> word is colored in red but when I type the last caractere the word is
> colored in green. The coloring should be appled on parameters, string
> (between 2 " or '), the color should be different if the word is
> alias, function or command.
>
> Thanks for your answer
>
> Nice day
> _____________________
> Michel BARRET
>
--
_________________________
< Murphy was an optimist. >
-------------------------
\ ,__,
\ (oo)____
(__) )\
||--|| *
Messages sorted by:
Reverse Date,
Date,
Thread,
Author