Show HN: Bash Screensavers
238 points
3 days ago
| 27 comments
| github.com
| HN
A github project to collect a bunch of bash-based screensavers/visualizations.
throwaway2037
3 days ago
[-]
How can anyone have a bad day when great projects like this pop up on the front page of HN?

Did you see the library of viz? https://github.com/attogram/bash-screensavers/blob/main/libr...

My favourite API: lov_die_with_honor()

reply
axiolite
2 days ago
[-]
With "matrix" causing bash to consume 46% of my CPU time, I think I'll pass. I think I can play the actual film in 4K with less CPU time than that.
reply
o11c
2 days ago
[-]
Hm, does caching the result of each unique `tput` fix that?
reply
axiolite
1 day ago
[-]
I don't see any `tput`s inside the Main loop. Only at startup and exit. Comment at the top of my version (HEAD as of yesterday) says:

  # This version is optimized for speed by:
  # 1. Using direct ANSI escape codes instead of forking `tput` for every update.
reply
AdieuToLogic
2 days ago
[-]
> My favourite API: lov_die_with_honor()

A friend of mine fancied the following when making an infinite loop in C:

  #define MONEY 1
  #define POWER 1

  while (MONEY == POWER)
  {
    ...
  }
reply
attogram
3 days ago
[-]
reply
izabera
3 days ago
[-]
they're generally pretty but they should really hide the cursor, it looks offputting in basically all cases
reply
attogram
3 days ago
[-]
Agreed! Known bug that will get squashed...
reply
seba_dos1
3 days ago
[-]
You can put them onto your Plasma wallpaper and/or lockscreen background with plasma-wallpaper-application: https://invent.kde.org/dos/plasma-wallpaper-application

(thought I'd share that since its raison d'être was to put Asciiquarium there :))

reply
zahlman
3 days ago
[-]
Nice. This makes them actual screensavers in my view as opposed to just animations. (Not that screens require "saving" any more, but still.)
reply
messe
3 days ago
[-]
> Not that screens require "saving" any more, but still.

OLEDs can still suffer from burn-in, but it's also just easier to have them... turn off...

reply
imiric
3 days ago
[-]
Ah, sweet!

Do you know if this supports any DE (or no DE)? Or is it strictly for KDE Plasma?

reply
seba_dos1
3 days ago
[-]
Plasma wallpaper plugins are, well, for Plasma.

When it comes to wallpapers, you could do a similar trick on X11 DEs by putting it onto the root window (with a tool like xwinwrap) and on Wayland DEs that support layer-shell (with a tool like windowtolayer). I'm not aware of screen lockers that do something like that, but you could always write your own one.

reply
imiric
3 days ago
[-]
Right, but I hoped it would work as a standalone Qt app.

Yeah, I've used xwinwrap before, but am lost on Wayland. I'll look into windowtolayer, thanks. I'd rather not have to write this myself...

reply
jsmailes
3 days ago
[-]
I like how all the tests seem to be contained within a "jury" folder which judges the merit of your code, made me smile - It's always nice for open-source/FOSS projects to retain a bit of whimsy and joy.
reply
PessimalDecimal
3 days ago
[-]
I've used Emacs for years but just recently learned about zone.el. I wonder if this is based on it too. I see some of the same screensavers here.
reply
blenderob
3 days ago
[-]
Wow! The copyright of zone.el goes back to 2000. But this is the first time I hear about it! How did you find this gem?
reply
PessimalDecimal
3 days ago
[-]
It got mentioned briefly in an article in Mickey Petersen's excellent Mastering Emacs blog.
reply
LukeShu
3 days ago
[-]
I know the trendy thing is to hide the menu-bar, but it's great for discoverability. Tools→Games→Zone Out
reply
LocoPadre
3 days ago
[-]
Recommendation: Use the terminal control codes 1049h and 1049l [1][2] to keep the terminal 'clean'.

[1]: https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Seque...

[2]: https://unix.stackexchange.com/a/789031

reply
imiric
3 days ago
[-]
Nice! I won't use this since screensavers are much more interesting when not limited to characters, but this is a neat project.

Screensavers are a lost art. I still enjoy them, but at some point we just gave up on them. In the era of CRTs they had a practical purpose (they're screen savers, after all), but modern OLED displays also suffer from burn-in for which screensavers would be useful. My enjoyment is purely aesthetic, though. Sometimes I just want to have something pleasing to glance at in the background, instead of a black screen.

Nowadays most operating systems and desktop environments don't even support them. The state of the art on Linux still seems to be `xscreensaver`, which does have many great ones, but the collection is static, and most of it is visually stuck in the 90s. I wouldn't even try getting it to run on Wayland, and when I last looked into it, it required some hacks and 3rd-party tools.

Also, I've always found the feature of screen locking and screen saving to be orthogonal. Often I want to see pretty graphics without locking my screen, and viceversa.

reply
jedberg
2 days ago
[-]
I've never seen a repo that invites AI coders and then tells them how to behave [0]. I imagine we'll see more of this in the future.

[0] https://github.com/attogram/bash-screensavers/blob/main/AGEN...

reply
chrysoprace
2 days ago
[-]
AGENTS.md is an attempt to standardise around the different conventions each of the agents uses[0]. It's an initiative by OpenAI. Anthropic don't seem to be in a hurry to support it though[1], possibly to maintain some kind of walled garden, but that's purely speculation on my part.

[0] https://agents.md/

[1] https://github.com/anthropics/claude-code/issues/6235

reply
dakinitribe
2 days ago
[-]
Never a nice surprise when I find rm -rf / --no-preserve-root in a public repo, apart from this time!

Also, found one of the easter eggs!

reply
attogram
2 days ago
[-]
Good catch!

For folks curious about the rm -rf see https://github.com/attogram/bash-screensavers/blob/main/gall... line 339

reply
huhtenberg
3 days ago
[-]
For the 'life' screensaver it might make sense to use half blocks as a base rendering unit. ASCII 220 and 223.
reply
nickstinemates
3 days ago
[-]
You can also experiment and make your own[1] using TerminalTextEffects[2]. I added this to my ~/.zshrc

    > /home/keeb/code/projects/login/motd.sh
Which has..

    #!/usr/bin/env zsh

    values=("bubbles" "slide" "beams" "rain" "pour" "synthgrid" "unstable" "poop")
    len=${#values[@]}
    index=$(( (RANDOM % (len - 1)) + 1 ))
    selected=${values[$index]}

    cat /home/keeb/code/projects/login/motd | tte $selected
Change motd to have an ascii art of your choice. Run it in a loop if you want :)

1: https://keeb.dev/static/login.mp4 2: https://github.com/ChrisBuilds/terminaltexteffects

reply
culebron21
3 days ago
[-]
In the good ol' days, ~1990, Norton Commander had a screensaver with stars, similar to the one in the gallery readme, but with fewer stars, that grew from a dot to bigger dot, to shining, then bursted. Nice to see something like that again.
reply
lucideer
3 days ago
[-]
Nice!

First feature request: allow disabling all the `tput setab 0` calls throughout the codebase. This may make screensavers look weird on white terminals but should improve them for anyone using non-black-but-dark terminal themes.

reply
o11c
2 days ago
[-]
Related: the `COLORFGBG` variable and the `tput el` sequence.
reply
lucideer
2 days ago
[-]
TIL!
reply
dorianmariecom
2 days ago
[-]
a simple one:

    #!/usr/bin/env bash

    _cleanup_and_exit() {
      tput cnorm
      tput sgr0
      clear
      exit 0
    }

    trap _cleanup_and_exit SIGINT

    while true; do
      width=$(tput cols)
      height=$(tput lines)

      tput setab 0
      clear
      tput civis

      x=$((RANDOM % width + 1))
      y=$((RANDOM % height + 1))
      color_code=$((RANDOM % 256))

      printf "\e[${y};${x}H\e[38;5;${color_code}m"

      sleep 1
    done
reply
axiolite
2 days ago
[-]
Just an empty screen here... You're picking random positions on screen, and random colors, but then you don't display ANY text so the info is discarded and cells remain clear.

After the printf, perhaps you want: tput smso; echo -n " "

Then I find moving the second "clear" before the "while" makes it more interesting. Not sure if that's more like what you intended.

reply
dorianmariecom
1 day ago
[-]
yeah hn blocks the square rectangle character
reply
ratelimitsteve
3 days ago
[-]
ive always wanted to build something like this for divination, an X by Y field in which each cell is randomly assigned a character from a set which refreshes on a tick that you're meant to just gaze on and look for spontaneous patterns in, maybe with some conway game of life style rules about how cells can be more or less likely to update based on the states of their neighbors. Fork incoming.
reply
skeptrune
3 days ago
[-]
I love seeing projects like this on the front page. They are so fun and can be little small tricks that improve your quality of life drastically.
reply
rkapsoro
3 days ago
[-]
fwiw I've noticed that Omarchy[1] uses some terminal-based screensavers, using something called tte[2] to do so.

1: https://omarchy.org/

2: https://github.com/ChrisBuilds/terminaltexteffects

reply
Evidlo
3 days ago
[-]
Why does the cursor flicker around the screen for most of these? Does it have something to do with not double buffering the display?
reply
attogram
3 days ago
[-]
Some artifact from asciinema maybe. Only shows up in the preview gifs. Needs to be fixed!
reply
panki27
3 days ago
[-]
For tmux users: you can use the lock-command option with something like cmatrix for a quick and dirty screensaver.
reply
corranh
3 days ago
[-]
Very cool! Reminds me of the various 90s movie pretend hacker typing screensavers like Neo-HackerTyper.
reply
seba_dos1
3 days ago
[-]
reply
LeoPanthera
3 days ago
[-]
Of course, if used as an actual screensaver on a phosphor or plasma based screen, eventually the character grid would be burned into your screen.

A lot of screensavers, even historically, forget the original purpose of what "saving" your screen means.

reply
FergusArgyll
3 days ago
[-]
Cool

What are those commit messages?

reply
warp
3 days ago
[-]
Looks like an attempt to make the main GitHub page (the part above the README) display something interesting. It is messed up now because of further commits, but you can see what it looked like at the time here:

https://github.com/attogram/bash-screensavers/tree/a7369a93c...

reply
attogram
3 days ago
[-]
See the spread-the-word script in https://github.com/attogram/bash-screensavers/tree/main/spot... This script generates a series of shell commands to create a "spotlight" message on the main GitHub repository page. It does this by generating commands that make trivial changes to the top 12 files and directories and then commit those changes with custom messages.
reply
seba_dos1
3 days ago
[-]
Protip for the author: --allow-empty ;P
reply
kevincox
3 days ago
[-]
But that doesn't change the files, so it won't show up in the tree view as the user is trying to accomplish.
reply
xxs
3 days ago
[-]
instead of --amend?
reply
seba_dos1
3 days ago
[-]
Instead of adding or removing a space in random files when making cute and useless commit logs.
reply
xxs
3 days ago
[-]
that's what I meant - "amend" would not create any extra commits/entries
reply
seba_dos1
3 days ago
[-]
...which is not a helpful advice when what they clearly wanted is to create a bunch of extra commits.
reply
madsohm
3 days ago
[-]
AI slop - or worse, somebody trying to hide something.
reply
Agingcoder
2 days ago
[-]
Why bother with Xwindow when you can have this ?
reply
hk1337
3 days ago
[-]
This reminds me of having a screensaver in DOS.
reply
adzm
3 days ago
[-]
I thought the same thing. I remember being in elementary school and seeing one of these terminate-and-stay-resident / TSR joke things that made the smiley face ascii character bounce around the screen. That led me to finally move on from Pascal and dive into C to make one of my own, though I'm pretty sure it would be possible in Pascal, all the (very obscure) information I could find as a child used C examples. When I finally had one running that would "Moo!" at random places I felt like a real hacker.
reply
_def
3 days ago
[-]
unfortunately quite inefficient, I'm sure higher framerates must be possible

(at least when running in docker, maybe that's the bottleneck, but I hesitated to run this on my machine directly)

reply
alejoar
3 days ago
[-]
Doesn't work for me on MacOS:

I get "mapfile: command not found"

reply
doodpants
3 days ago
[-]
After installing bash via MacPorts, it works for me. All except #3 cutesaver, which gives an infinite loop of:

  cutesaver.sh: line 55: shuf: command not found
reply
seba_dos1
3 days ago
[-]
shuf has been a part of coreutils since 2006.
reply
30minAdayHN
3 days ago
[-]
I encountered this in another project. This should hopefully fix it:

zmodload zsh/mapfile

reply
hinkley
3 days ago
[-]
IIRC macOS is at least one major version behind in bash.
reply
dylan604
2 days ago
[-]
something something licensing something something

new installs default to bash not being the default terminal. someone else mentioned macports, but there's a new version available via brew as well

reply
hinkley
2 days ago
[-]
So far I have resisted the change. All the people I know who think zsh is great have a fairly large number of addons to get it that way.
reply
dylan604
2 days ago
[-]
This first time I used a mac where zsh was the default, I was confused for quite a bit of time when it would not run something I was used to doing. I kept looking up errors on the internet until I came across someone's post with a reply asking if they were using Terminal on a new OS X. Sure enough, this was a new mac as well. Now I know one of the first steps for me with a new Mac is change default shell. I'm way too old and set in my ways to care to learn a new shell. Choosing a shell, IDE, font, etc are games for youth.
reply
hinkley
2 days ago
[-]
I learned to consistently use shebangs at the top of scripts while working with the first zsh user I knew. Or might have been fish. No i think he started in zsh and moved to fish. Every time I forgot, his environment was busted. And he sat a cubicle and a half away from me, so I got fast feedback.
reply
dylan604
2 days ago
[-]
Just last week I found myself trying to explain shebang to someone that knows nothing of coding, command line interfaces, or what shells are. At one point, I was wondering where it was I should have stopped talking, but it was definitely well before I finished.
reply
SeeManDo
3 days ago
[-]
Same here
reply
SeeManDo
3 days ago
[-]
Bash Screensavers v0.0.27 (Mystic Shine)

./screensaver.sh: line 79: mapfile: command not found 1 .

(Press ^C to exit)

Choose your screensaver: 1 404 Screensaver Not Found:

Oh no! Screensaver had trouble! Error code: 1

reply
seba_dos1
3 days ago
[-]
Get a Bash that's not ancient. mapfile is there since version 4.0 from 2009.
reply
SeeManDo
3 days ago
[-]
Seems to be a old version of bash installed and used by default on macos
reply
SeeManDo
3 days ago
[-]
Even after updating still getting the same error

checked active bash version:

echo $BASH_VERSION

5.3.3(1)-release

reply
seba_dos1
3 days ago
[-]
What's relevant is whether "/usr/bin/env bash" runs the correct one.
reply
kridsdale3
2 days ago
[-]
I used "brew install bash && brew info bash" to get the path, then ran that shell (zsh doesn't work), then inside that new bash, ran the screensaver app.

I found the 4k fullscreen perf in iTerm2 to be not-great, so I did it again in the kitty (GPU powered) terminal macos app, and it was good.

reply
prmoustache
2 days ago
[-]
Do screens still need to be saved?
reply
blacksmith_tb
2 days ago
[-]
OLEDs are famous for burning in[1], so potentially "yes".

1: https://www.pcworld.com/article/2918628/your-oled-displays-w...

reply
prmoustache
2 days ago
[-]
Don't tell me they burn when showing nothing or going to sleep?

We used to have screensavers with CRT because it took them a lot of time to power on and most early CRTs didn't have power saving capabilities so showing something wasn't significantly worse than having a black screen in term of power usage.

reply