Search code examples
linuxbashunixpromptps1

Animated PS1 prompt BASH


I'm aware that this has been asked before but I couldn't find the answer I wanted anywhere. What I need (would like to have) is a BASH prompt that looks like this:

[ blah@blah ] >
[ blah@blah ]  >
[ blah@blah ]   >

(then the animation repeats) Its just for the life of me I can't figure it out and I've been searching for days (apparently not too many people don't want an animated prompt). What I want it to do is go through one frame of the animation every 1/2 second so every full animation would be 1 1/2 seconds long.

Is there any way I can do this? Thanks in advance and sorry if the way I explained it was a bit confusing.


Solution

  • This is what I got:

    animation() {
    S="\033[s"
    U="\033[u"
    
    POS="\033[1000D\033[2C"
    while [ : ]
    do
        eval echo -ne '${S}${POS}\>\ \ ${U}'
        sleep 0.3
        eval echo -ne '${S}${POS}\ \>\ ${U}'
        sleep 0.3
        eval echo -ne '${S}${POS}\ \ \>${U}'
        sleep 0.3
    done
    }
    PS1='[     ] : [ \u @ \h ] > '
    animation &
    

    I slightly modified a script from one of the links so you just put this into a file and source it or paste it into a terminal to get a simple animated prompt.