SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-04-21 10:51:03

Athos
#! CrunchBanger
Registered: 2011-09-28
Posts: 108

Run functions when pressed enter?

Hi everybody, while playing with the zsh prompt, I had an idea, since, having only one color, is kind of boring...(:D) Why not randomize the color?

And so I did:
tZGdlcw

The problem, as you can see is that it only gets one color everytime zsh is called, and I want to have it different everytime!

So, here's my prompt, (and the functions):

random_color(){
    random -e 7
    case $? in
        0) color=$white;;
        1) color=$green;;
        2) color=$blue;;
        3) color=$cyan;;
        4) color=$magenta;;
        5) color=$yellow;;
        6) color=$red;;
    esac
}
random_color
number_col="%(?.$green%?.$red$?)$reset"
path_col="$color%d$reset"

PROMPT="┌─[$number_col]─[$path_col]
└╼ "

Any ideas, anyone?

Offline

Be excellent to each other!

#2 2012-04-23 07:08:41

AlanD
#! CrunchBanger
Registered: 2011-05-12
Posts: 116

Re: Run functions when pressed enter?

Are you calling that with the zsh precmd  function? It runs each time just before the prompt is refreshed, much like bash's PROMPT_COMMAND

Last edited by AlanD (2012-04-23 07:23:41)

Offline

#3 2012-05-07 13:50:51

Athos
#! CrunchBanger
Registered: 2011-09-28
Posts: 108

Re: Run functions when pressed enter?

Many thanks! big_smile

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo