Bashsimplecurses: Simple curses library made in bash to draw terminal interfaces
github.com
github.com
One oft overlooked feature is bash supports dynamically loadable 'builtins' as shared object modules so it wouldn't take much to create a 'proper' wrapper around libncurses.
Debian and derivatives have the package "bash-builtins" that has a lot of examples including wrapping/implementing many coreutils tools.
Aside: I've wondered aloud if we could figure out how to systemically compile coreutils into true bash builtins for performance benefits in nix builds, but someone did rightly point out that builtins can't be completely fungible with a separate process in all cases, especially where stuff like pipelines are involved. I don't recall the exact details and couldn't readily find the conversation but IIRC it had to do with signal handling.
Edit: Found the conversation: https://gist.github.com/abathur/74e7a63b25b7bbd4a6fa9ad7e728...
2+ decades of daily bash usage, and TIL...
Any good (short) reads on how ones does this? I can think of a few things that I'd like native in the shell.
https://git.savannah.gnu.org/cgit/bash.git/tree/examples/loa...
So I love TUIs.
That said, I'm always a little puzzled about why people build these libraries in bash. Is it simply curiosity? Maybe, and if so, godspeed.
But if it's driven by pragmatism, let me assure the reader that if there are limits to the extents I will go to get python somewhere instead of writing even a somewhat nontrivial bash script, I have yet to find them. Not only is bash just kind of really annoying to program in, it's also nearly unethical to program in. Let me link the 2 I always link to when someone tells me they're "working on" a bash script.
Steam deleted my entire system (empty variable expansion): https://github.com/valvesoftware/steam-for-linux/issues/3671
Bumblebee deletes /usr due to space: https://www.reddit.com/r/softwaregore/comments/2hsdo6/giant_...
So I warn people: if you use python, you'll categorically avoid being the third entry in my list.
On VM's you can use pyenv for a local Python installation if you don't want to install it globally.
In Docker vanilla, you can run another container with Python that uses the same namespaces (ipc, pid, network) as your other running container without Python.
There are options. If your security team forbids Python for some reason, I would wonder why they are letting systems have bash/curl/etc on them.
Curses in itself needs so much boilerplate that I usually just go to the libraries rich or textual instead.
I've used zsh/curses a few times to hack together little interfaces, and it is quite workable. It makes things far simpler once you start reaching for terminfo's capabilities that require you to think about state too much. A friend of mine wrote a little mblaze⁴ frontend using it, and it felt like using single mailbox mutt with less than a hundred lines of code.
I was expecting the linked project to be a loadable module too given that bash also supports them, but it is actually a little more interesting to look at given it implements a bunch of the behaviour itself on top of tput calls.
¹ https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-...
² https://github.com/zsh-users/zsh/blob/master/Functions/Misc/...
³ https://github.com/zsh-users/zsh/blob/master/Functions/Misc/...
Without just using #!/bin/sh (or some trick with env that may also not be portable), then having a large fancy function to test for current shell identity and tries to search for & respawn with something else if that does not seem to be suitably compatible?
The project has bash on its name - it is not as if it is pretending to be more generic, or written by someone who has always had bash linked from /bin/sh and knows no better.
#!/usr/bin/env bash"topify"
... which is the word I would use to describe a primitive that will take line inputs from stdio and display them in a 'top' style output, presumably with curses.
Maybe there is more complication here than I have thought out but ... if I can output a standard line with columns I have already defined (perhaps in an 'awk' pipeline or whatever) then I would like a way to refresh them, in some order.
I am fairly certain this does not exist ...
Admittedly, it isn't quite a drop in replacement, but the usage is close enough that even aliasing it is unlikely to cause [many] problems.
I'm not sure.
I've been directed to this in the past but I have a vague sense that it didn't do what I was looking for.
I will take another look ...