Create a gist now

Instantly share code, notes, and snippets.

@sontek /snowjob.sh
Last active Apr 25, 2018

What would you like to do?
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear
function move_flake() {
i="$1"
if [ "${snowflakes[$i]}" = "" ] || [ "${snowflakes[$i]}" = "$LINES" ]; then
snowflakes[$i]=0
else
if [ "${lastflakes[$i]}" != "" ]; then
printf "\033[%s;%sH \033[1;1H " ${lastflakes[$i]} $i
fi
fi
printf "\033[%s;%sH\u274$[($RANDOM%6)+3]\033[1;1H" ${snowflakes[$i]} $i
lastflakes[$i]=${snowflakes[$i]}
snowflakes[$i]=$((${snowflakes[$i]}+1))
}
while :
do
i=$(($RANDOM % $COLUMNS))
move_flake $i
for x in "${!lastflakes[@]}"
do
move_flake "$x"
done
sleep 0.1
done
@sontek

This comment has been minimized.

Show comment Hide comment
@sontek

sontek Dec 21, 2011

If your terminal font supports it you can replace * at line 22 with ❄ to make it more festive

Owner

sontek commented Dec 21, 2011

If your terminal font supports it you can replace * at line 22 with ❄ to make it more festive

@amstan

This comment has been minimized.

Show comment Hide comment
@amstan

amstan Dec 21, 2011

Can you make it appear on top of something that's already running?

amstan commented Dec 21, 2011

Can you make it appear on top of something that's already running?

@x37v

This comment has been minimized.

Show comment Hide comment
@x37v

x37v Dec 21, 2011

awesome!

x37v commented Dec 21, 2011

awesome!

@allaun

This comment has been minimized.

Show comment Hide comment
@allaun

allaun Dec 21, 2011

I named the script as snowjob, and this is the output?
snowjob: 11: Syntax error: "(" unexpected

allaun commented Dec 21, 2011

I named the script as snowjob, and this is the output?
snowjob: 11: Syntax error: "(" unexpected

@supercheetah

This comment has been minimized.

Show comment Hide comment
@supercheetah

supercheetah Dec 21, 2011

Like it!

Like it!

@sontek

This comment has been minimized.

Show comment Hide comment
@sontek

sontek Dec 21, 2011

@allaun What shell are you using? You can replace function move_flake() with function move_flake (removing the parens) and it'll work for you

Owner

sontek commented Dec 21, 2011

@allaun What shell are you using? You can replace function move_flake() with function move_flake (removing the parens) and it'll work for you

@EmbeddedLinuxGuy

This comment has been minimized.

Show comment Hide comment
@EmbeddedLinuxGuy

EmbeddedLinuxGuy Dec 22, 2011

Nice. Also you can rotate different flake glyphs if you replace * with \u274"$[($RANDOM%6)+3]"

Nice. Also you can rotate different flake glyphs if you replace * with \u274"$[($RANDOM%6)+3]"

@sontek

This comment has been minimized.

Show comment Hide comment
@sontek

sontek Dec 22, 2011

@EmbeddedLinuxGuy That is awesome, thanks!

Owner

sontek commented Dec 22, 2011

@EmbeddedLinuxGuy That is awesome, thanks!

@skihero

This comment has been minimized.

Show comment Hide comment
@skihero

skihero Dec 22, 2011

cool!

skihero commented Dec 22, 2011

cool!

@ggustafsson

This comment has been minimized.

Show comment Hide comment
@blottis

This comment has been minimized.

Show comment Hide comment
@blottis

blottis Nov 19, 2015

Thanks for the script it is very cool, but could you provides us with some additional info about how to make it more functional ... for example how to make the snow appear on a functional terminal screen as @amstan stated in his comment. I am new with bash scripting and want to use your code to decorate a script I am creating but I can not deduce where to put my code... thanks

blottis commented Nov 19, 2015

Thanks for the script it is very cool, but could you provides us with some additional info about how to make it more functional ... for example how to make the snow appear on a functional terminal screen as @amstan stated in his comment. I am new with bash scripting and want to use your code to decorate a script I am creating but I can not deduce where to put my code... thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment