0

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.

QuaDECH
  • 15
  • 1
  • 8
  • The only thing I want less than an animated prompt is an animated prompt that beeps at me ;) This might help: http://stackoverflow.com/questions/29448625/how-to-make-an-animated-bash-shell-prompt-for-the-terminal. Or this [Two-cent tip](http://linuxgazette.net/168/misc/lg/two_cent_tip__bash_script_to_create_animated_rotating_mark.html) – paulsm4 Jun 02 '15 at 22:16
  • I agree with chepner in that linked question. I don't believe this is possible. At least not without writing a script that displays your own prompt (which may or may not actually be possible in a reliable and safe manner). You could get the prompt string to move to a different position on each *new* prompt line in a rotating pattern but I don't think that's what you meant. – Etan Reisner Jun 02 '15 at 22:23
  • Grab the bash sources from ftp://ftp.gnu.org/gnu/bash/ and modify them. That's the only way I can think of to do what you want. (And **please** turn it off before asking me to look at your screen.) – Keith Thompson Jun 02 '15 at 22:39
  • Thanks guys for the tips and links. I think I figured it out – QuaDECH Jun 02 '15 at 22:54

1 Answers1

0

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.

QuaDECH
  • 15
  • 1
  • 8
  • 1
    Overlaying characters into other applications' output (when something other than the prompt is active at a third-of-a-second boundary) is rather a nasty side effect, no? – Charles Duffy Jun 02 '15 at 23:07
  • To prevent that, one might need to use a DEBUG trap that turns off the effect and a `PROMPT_COMMAND` that starts it again... though care will need to be used to prevent the DEBUG trap from being called during the execution of the PROMPT_COMMAND itself. – Charles Duffy Jun 02 '15 at 23:13