-- Leo's gemini proxy

-- Connecting to warmedal.se:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; lang=en

Program Picker With Zenity


Zenity is a small utility program for building simple graphical widgets and menus. I've never had use for it before, but a few days ago I ran into a situation that it just so happened to be perfect for.


I have a program of which I currently have several different versions compiled. Stable, release candidate, latest, etc. Since I start pretty much everything through gmrun (look that up: it's the best part of searching in the Gnome 3 menu, but without the bloat of Gnome 3) I didn't want to have to remember which versions I currently have. Wouldn't it just be better to run a command and pick from the currently available builds?


Enter zenity. This is a small script that for example purposes will be called /usr/bin/exampleprog


#!/bin/bash

cd /home/bjorn/exampleprog-builds

VERSION=$(zenity --list --title "" --text "Choose version" --column Version --hide-header *)

if [[ -n $VERSION ]]; then
        cd "$VERSION"
        ./start
fi


That zenity command is genuinely beautiful. Here's what the arguments mean:


--list means we want a list widget

--title "" sets a title for the top panel of the window. I set this to an empty string, as you can see.

--text "Choose version" gives the text above the list of choices.

--column Version means we have one column, and it's named Version. You can add more columns by just adding more column names.

--hide-header means that we don't need to see the headers of our columns.

The asterisk is of course a bash expansion, which means that all the file and folder names in the current working directory become the rest of our arguments, and they will be sorted into our columns (which is just a single column in our case) as available choices.


This will produce a small window with a list that has a vertical scrollbar if needed. One entry in the list can be chosen, and there is a Cancel and an OK button.


If the user picks an element from the list and clicks OK that element will be returned from zenity. This is why I assign the output from zenity to the VERSION environment variable. If that output is a non-zero string we can use it, otherwise we just terminate gracefully.


-- CC0 ew0k, 2023-01-03

-- Response ended

-- Page fetched on Sat May 4 13:38:47 2024