Show HN: Termipal – native micro-GUIs for shell scripts and command line apps
termipal.sh
termipal.sh
http://web.uvic.ca/~ncs/406/HTML/Targeting_MacOS/images/IDE1...
CDE's DtKsh, which has had support for this for decades. http://www.brendangregg.com/dtkshdemos.html
I feel a bit sad that I was unable to put in the work to bring Electrino forward. There was a lot of interest, but I just couldn't find any more extra time between existing paying work and family. As you say, Electrino is a multi-year commitment because of the sheer number of APIs needed to support the apps that are already out there.
I made Termipal because I found myself writing a bunch of crappy shell scripts for various tasks, and having real UI with dropdowns and buttons made the scripts much more usable.
I used to be a native dev (from when native meant desktop OS :P) and switched to web apps just for UI development convenience, then node-webkit came. I still use both nw.js and Electron (though I admit I kinda like nw.js more, IPC is a PITA) but, even though I love the development experience, I absolutely hate the end user experience.
Can you elaborate on why is Electrino a multi-year commitment? I guess I can see why if you meant Electrino as a drop-in replacement of Electron. Did you consider scaling down the features a bit? Just bundle a native webview + Node.js, add some kind of IPC and let userland do the rest.
Would this be achievable or am I missing something that makes it way harder than I imagine?
EDIT: After scanning my own comment I see why... the idea is to not bundle Node.js and instead use the native JS engine which does not include Node APIs nor leverages the NPM ecosystem.
What's so special about the terminal is the immunity the user has to hostile character strings.
When I view a webpage in lynx or read an email in (al)pine, there is no string that could be injected to harm me - I am immune to viruses and javascript and weird CSS and so on. I can open up an infected document or view a phishing email.
In short, the well-behaved terminal does nothing but display text in your character set. It does not interpret and it does not execute and it certainly doesn't call GUI APIs to draw buttons and display videos.
This is a door best left unopened ...
This could potentially add a new attack surface, sure, but don't think that without it, exploits aren't possible.
I have a handful of escape codes that beg to differ...
Unfortunately that's not true at all. There are many instances of arbitrary code execution gained though a terminal emulator, with escape sequences[1] being the most common. For example exploiting common "git prompts"[2] scripts or running `strings` on a binary[3].
[1]: https://unix.stackexchange.com/a/15210
[2]: https://github.com/njhartwell/pw3nage
[3]: http://lcamtuf.blogspot.it/2014/10/psa-dont-run-strings-on-u...
It's worth noting, however, that there is nothing inherently dangerous about a strings-like utility. Rather, it is GNU strings which has unexpected complexity:
"Perhaps simply by the virtue of being a part of that bundle, the strings utility tries to leverage the common libbfd infrastructure to detect supported executable formats and "optimize" the process by extracting text only from specific sections of the file. Unfortunately, the underlying library can be hardly described as safe: a quick pass with afl (and probably with any other competent fuzzer) quickly reveals a range of troubling and likely exploitable out-of-bounds crashes due to very limited range checking"
... which is the very issue I'm warning against, just at a different layer of abstraction ...
- Terminals are the worth offenders when it comes to special characters and encoding issues.
- GUIs are not inherently injectable.
That said, I still things it's a weird idea. There are much better ways to gain efficiencies (e.g. shells)
The whole problem is that shells are REPLs, and REPLs are not the best method of interaction. This idea could probably be taken even farther.
What does Termipal do if you have terminal full screen?
rterrell$ /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
>>> for (var i=0; i<10; i++) { print("Hello World!", i); }
Hello World! 0
Hello World! 1
Hello World! 2
Hello World! 3
Hello World! 4
Hello World! 5
Hello World! 6
Hello World! 7
Hello World! 8
Hello World! 9
undefined
>>>
Edit to add: the submission reminds me of the old "Commando" for MPW. Very cool.* [JXA Cookbook](https://github.com/JXA-Cookbook/JXA-Cookbook)
* [JavaScript OS X App Examples](https://github.com/tylergaw/js-osx-app-examples)
For my application (URL in bio), I wrote a shell script that (mostly) automatically generates the screenshots for the Mac App Store. It uses osascript(1) with some JS to set the system colors/wallpaper/language to a particular style, position the app window where I want it, take a screenshot, block out my menubar extras, crop it to the requested size, etc.
OSA scripting is actually pretty powerful, but sadly the documentation is awful. Try:
osascript -l JavaScript -e 'Application("System Events").appearancePreferences.appearance = "graphite"'
(or "blue")[1]: https://en.wikipedia.org/wiki/AppleScript#JavaScript_for_Aut...
A neat feature would be a dialog (the tui cursors one) fallback, I.e. when working over SSH.
Anyway, Termipal's benefits are:
* Native Cocoa widgets
* No dependencies (uses system JavaScript framework)
* Attaches to host terminal window to minimize UI transitions.
It's designed for tiny non-intrusive GUIs invoked as part of a script. Tk probably shines for more complex dialogs.
For invoking shell commands, it would probably be best to just implement Node's child_process module?
Adding more APIs is in general not difficult -- it's harder to decide what to prioritize.
This is a beaut :)
It attaches to the focus window on the app that launched it, so it should be terminal-agnostic.
Here's the Github repo: https://github.com/pojala/termipal