Screen saver for your Shell

Dec. 28, 2013, 5:01 a.m.


Playing with cursor and colors

Cursor Bounce

Cursor will bounce off the walls of your terminal. Try resizing your terminal while its in the middle of the terminal.
x=1;y=1;xd=1;yd=1;while true;do if [[ $x == $LINES || $x == 0 ]]; then xd=$(( $xd *-1 )) ; fi ; if [[ $y == $COLUMNS || $y == 0 ]]; then yd=$(( $yd * -1 )) ; fi ; x=$(( $x + $xd )); y=$(( $y + $yd )); printf "\33[%s;%sH" $x $y; sleep 0.02 ;done 

Rainbow Cursor Worm

Cursor leaves a rainbow trail behind it.
a=1;x=1;y=1;xd=1;yd=1;while true;do if [[ $x == $LINES || $x == 0 ]]; then xd=$(( $xd *-1 )) ; fi ; if [[ $y == $COLUMNS || $y == 0 ]]; then yd=$(( $yd * -1 )) ; fi ; x=$(( $x + $xd )); y=$(( $y + $yd )); printf "\33[%s;%sH\33[48;5;%sm \33[0m" $x $y $(($a%199+16)) ;a=$(( $a + 1 )) ; sleep 0.001 ;done

Terminal Screen Saver

Full terminal color gradient effects. The modulus operations keep the colors cycling a bit and makes sure it repeats itself after producing some horizontal lines. Probably could be reworked to be a bit better, this is an exercise left to the hacker.
j=0;a=1;x=1;y=1;xd=1;yd=1;while true;do for i in {1..2000} ; do if [[ $x == $LINES || $x == 0 ]]; then xd=$(( $xd *-1 )) ; fi ; if [[ $y == $COLUMNS || $y == 0 ]]; then yd=$(( $yd * -1 )) ; fi ; x=$(( $x + $xd )); y=$(( $y + $yd )); printf "\33[%s;%sH\33[48;5;%sm . \33[0m" $x $y $(( $a % 8 + 16 + $j % 223 )) ;a=$(( $a + 1 )) ; done ; x=$(( x%$COLUMNS + 1 )) ; j=$(( $j + 8 )) ;done

Making it a command

  1. Editing .bashrc or .profile to make the screen saver work on a command you may edit .bashrc or .profile (if you are using ubuntu) using one of your favourite text editor here we are using vi:
    $ vi ~/.bashrc
  2. Put the following content in .bashrc if you are using Ubuntu .profile
    function run_scr(){
       j=0;a=1;x=1;y=1;xd=1;yd=1;while true;do for i in {1..2000} ; do if [[ $x == $LINES || $x == 0 ]]; then xd=$(( $xd *-1 )) ; fi ; if [[ $y == $COLUMNS || $y == 0 ]]; then yd=$(( $yd * -1 )) ; fi ; x=$(( $x + $xd )); y=$(( $y + $yd )); printf "\33[%s;%sH\33[48;5;%sm . \33[0m" $x $y $(( $a % 8 + 16 + $j % 223 )) ;a=$(( $a + 1 )) ; done ; x=$(( x%$COLUMNS + 1 )) ; j=$(( $j + 8 )) ;done &
    main=$!
    tput smso
    echo "Press any key to return \c"
    tput rmso
    oldstty=`stty -g`
    stty -icanon -echo min 1 time 0
    dd bs=1 count=1 >/dev/null 2>&1
    stty "$oldstty"
    echo
    clear
    clear
    kill $main
    }
    alias screensaver=run_scr
  3. Close the session and open it again, or simply reload the .bashrc configuration
  4. To enable to screen saver type the following command string:
    $ screensaver
  5. To stop it press any key or CTRL+C
NOTE: These calls are not compatible with all linux distros.