Last active
August 9, 2024 13:14
-
-
Save sontek/1505483 to your computer and use it in GitHub Desktop.
Make your terminal snow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Yea new revision doesnt work for me either but old revision works great
Wow, interesting that others are finding this today. I've done a lot of work on this over the years and its currently packaged over here:
I think people are finding it through a python implementation that got to hackernews front page https://news.ycombinator.com/item?id=38652339
Oh thats also yours hahaha @sontek
For people on MacOS that the new version isn't working on, it's due to the bash version shipping with macOS being too old to support unicode escape.
If you have a newer version of bash installed in homebrew you can change the bang at the top e.g. #!/opt/homebrew/bin/bash
(or use the author's python version)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@heyarviind @alaz-aura @sandippingle the previous revision works: https://gist.github.com/sontek/1505483/ed3449161c88f3ca5f96c1286009fc68d326d4e8