From: Roy Zuo <roylzuo@gmail.com>
To: Michel <michel.barret@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Dynamic colored command in zsh
Date: Mon, 13 Sep 2010 21:03:45 +0800 [thread overview]
Message-ID: <20100913130345.GA9240@Lancelot> (raw)
In-Reply-To: <AANLkTinNJXay4pibEiQmKR4PSRcNiwCJ3w==Scc9rco0@mail.gmail.com>
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)____
(__) )\
||--|| *
next prev parent reply other threads:[~2010-09-13 13:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-12 10:04 Michel
2010-09-13 13:03 ` Roy Zuo [this message]
2010-09-13 13:25 ` Julien Nicoulaud
2010-09-13 13:44 ` Roy Zuo
2010-09-13 14:14 ` Sebastian Stark
2010-09-13 14:34 ` Julien Nicoulaud
2010-09-18 16:03 ` Richard Hartmann
2010-09-18 23:09 ` Roy Zuo
2010-09-18 23:58 ` Michel
2010-09-19 11:50 ` Julien Nicoulaud
2010-09-19 14:39 ` Mikael Magnusson
2010-09-19 14:55 ` Mikael Magnusson
2010-09-13 14:16 ` Frank Terbeck
2010-09-13 23:33 ` Roy Zuo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100913130345.GA9240@Lancelot \
--to=roylzuo@gmail.com \
--cc=michel.barret@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).