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

Re: Dynamic colored command in zsh



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