On the scale of care, “the script can blow up in surprising ways” severely outweighs “error messages are in red.” Also, as someone else pointed out, what if I’m redirecting to a file?
Techniques I use to create a great user experience for shell scripts
21–30 of 281 posts
Re: Techniques I use to create a great user experience for shell scripts
#22Use a better programming language. Go, Typescript, Rust, Python, and even Perl come to mind.
Re: Techniques I use to create a great user experience for shell scripts
#23Every time I see a “good” bash script it reminds me of how incredibly primitive every shell is other than PowerShell. Validating parameters - a built in declarative feature! E.g.: ValidateNotNullOrEmpty. Showing progress — also built in, and doesn’t pollute the output stream so you can process returned text AND see progress at the same time. (Write-Progress) Error handling — Try { } Catch { } Finally { } works just l…
PowerShell can be embedded into a process as a library... and used to build an entire GUI that just wraps the CLI commands.
Sounds pretty interesting. Can you tell me what search terms I'd use to learn more about the GUI controls? Are they portable to Linux?Re: Techniques I use to create a great user experience for shell scripts
#24Not trying to offend anyone here but I think shell scripts are the wrong solution for anything over ~50 lines of code. Use a better programming language. Go, Typescript, Rust, Python, and even Perl come to mind.
Re: Techniques I use to create a great user experience for shell scripts
#25 if [ "$(uname -s)" == "Linux” ]; then
stuff-goes-here
else # Assume MacOS
While probably true for most folks, that’s hardly what I’d call great for everybody not on Linux or a Mac.Re: Techniques I use to create a great user experience for shell scripts
#26I was so frustrated by having to enter a lot of information for every new git project (I use a new VM for each project) so I wrote a shell script that automates everything for me. I'll probably also combine a few git commands for every commit and push.
Sounds like a cool setup! Did you write it up somewhere publicly? I also use VMs (qemu microvms) based on docker images for development.
I asked ChatGPT to write it and double checked btw.
Re: Techniques I use to create a great user experience for shell scripts
#27if [ "$(uname -s)" == "Linux” ]; then stuff-goes-here else # Assume MacOS While probably true for most folks, that’s hardly what I’d call great for everybody not on Linux or a Mac.
Re: Techniques I use to create a great user experience for shell scripts
#28Every time I see a “good” bash script it reminds me of how incredibly primitive every shell is other than PowerShell. Validating parameters - a built in declarative feature! E.g.: ValidateNotNullOrEmpty. Showing progress — also built in, and doesn’t pollute the output stream so you can process returned text AND see progress at the same time. (Write-Progress) Error handling — Try { } Catch { } Finally { } works just l…
PowerShell can be embedded into a process as a library... and used to build an entire GUI that just wraps the CLI commands. Sounds pretty interesting. Can you tell me what search terms I'd use to learn more about the GUI controls? Are they portable to Linux?
The .NET library for this is System.Management.Automation.
You can call a PowerShell pipeline with one line of code: https://learn.microsoft.com/en-us/dotnet/api/system.manageme...
Unlike invoking bash (or whatever) as a process, this is much lighter weight and returns a sequence of objects with properties. You can trivially bind those to UI controls such as data tables.
Similarly the virtual file system providers expose metadata programmatically such as “available operations”, all of which adhere to uniform interfaces. You can write a generic UI once for copy, paste, expand folder, etc and turn them on or off as needed to show only what’s available at each hierarchy level.
As an example, the Citrix management consoles all work like this. Anything you can do in the GUI you can do in the CLI by definition because the GUI is just some widgets driving the same CLI code.
Re: Techniques I use to create a great user experience for shell scripts
#29Don't output ANSI colour codes directly - your output could redirect to a file, or perhaps the user simply prefers no colour. Use tput instead, and add a little snippet like this to the top of your script: command -v tput &>/dev/null && [ -t 1 ] && [ -z "${NO_COLOR:-}" ] || tput() { true; } This checks that the tput command exists (using the bash 'command' builtin rather than which(1) - surprisingly, which can't alwa…
Re: Techniques I use to create a great user experience for shell scripts
#30if [ "$(uname -s)" == "Linux” ]; then stuff-goes-here else # Assume MacOS While probably true for most folks, that’s hardly what I’d call great for everybody not on Linux or a Mac.
That said, I’ve never used any of the BSDs, so I may be way off here.