Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Dynamic colored command in zsh
- X-seq: zsh-users 15409
- From: Roy Zuo <roylzuo@xxxxxxxxx>
- To: Richard Hartmann <richih.mailinglist@xxxxxxxxx>
- Subject: Re: Dynamic colored command in zsh
- Date: Sun, 19 Sep 2010 07:09:45 +0800
- Cc: Julien Nicoulaud <julien.nicoulaud@xxxxxxxxx>, Sebastian Stark <seb-zsh@xxxxxxxxxxx>, Michel <michel.barret@xxxxxxxxx>, 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=Cr8RZpo7gOUFEqURI8PJq8Ch85Wy2huLO2XCEB4Qvuc=; b=g0jT8tZdYzIq1NplkkccXHZnwl3MTukcp5Y2rfBI+hoq2+JsQ4kmHwOfZ9coRiaTQn n6yrvVnKT7FbjgBKrRGahbPcY4EKg+MP6U/iuAJGIueBQqpVOhwpJR5YSj6trIkrDCYq KIV3O9rE6c4PCe2YqYVyNFrhpGkPe1ANZUwKw=
- 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=EcnIZl1rRn4fngdXpQU65uGlB9AEtx8g1LHcsy7b0hTCIBqNr//OcQ2WAK1aB8+FJw 3hcB201al45AHYls+I4GsNxS/konBw95f4p5julrbjD3douND81IVb/3w2ElUDnpnIPb T6Ggp4LdurUpLGbmUsvZ6z7t7d3CCoRTQtOis=
- In-reply-to: <AANLkTi=28cEq+XhxCy7pYKtu+bmSNG3QSKMfBUckJ7Tc@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: Richard Hartmann <richih.mailinglist@xxxxxxxxx>, Julien Nicoulaud <julien.nicoulaud@xxxxxxxxx>, Sebastian Stark <seb-zsh@xxxxxxxxxxx>, Michel <michel.barret@xxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <AANLkTinNJXay4pibEiQmKR4PSRcNiwCJ3w==Scc9rco0@xxxxxxxxxxxxxx> <20100913130345.GA9240@Lancelot> <AANLkTikq=h-awW+-HAB8-QWdg0dWTuY+uydMu-Ezmt-0@xxxxxxxxxxxxxx> <6227C736-CCD3-4E09-A922-106573F3D70D@xxxxxxxxxxx> <AANLkTimj6n_qSd3_5Egk6RN=v47GwWBb+W3_MjWpMs4t@xxxxxxxxxxxxxx> <AANLkTi=28cEq+XhxCy7pYKtu+bmSNG3QSKMfBUckJ7Tc@xxxxxxxxxxxxxx>
Not exactly the same code, but the same feature and less bugs.
recolor-cmd() {
region_highlight=()
colorize=true
start_pos=0
for arg in ${(z)BUFFER}; do
((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
((end_pos=$start_pos+${#arg}))
if $colorize; then
colorize=false
res=$(LC_ALL=C builtin type $arg 2>/dev/null)
case $res in
*'reserved word'*) style="fg=magenta,bold";;
*'alias for'*) style="fg=cyan,bold";;
*'shell builtin'*) style="fg=yellow,bold";;
*'shell function'*) style='fg=green,bold';;
*"$arg is"*)
[[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold";;
*) style='none,bold';;
esac
region_highlight+=("$start_pos $end_pos $style")
fi
if [[ $arg = '|' ]] || [[ $arg = 'sudo' ]]; then
colorize=true
fi
start_pos=$end_pos
done
}
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
Roy
On Sat, Sep 18, 2010 at 06:03:42PM +0200, Richard Hartmann wrote:
> On Mon, Sep 13, 2010 at 16:34, Julien Nicoulaud
> <julien.nicoulaud@xxxxxxxxx> wrote:
>
> > I created a collaborative notepad, feel free to improve it:
> > http://ethercodes.com/zDUmDAuWiV
>
> That link does not seem to work, any more.
>
>
> Richard
>
--
____________________________________________________________
/ Nothing will dispel enthusiasm like a small admission fee. \
| |
\ -- Kim Hubbard /
------------------------------------------------------------
\ ,__,
\ (oo)____
(__) )\
||--|| *
Messages sorted by:
Reverse Date,
Date,
Thread,
Author