Create a select menu with smenu
Multiple Choice
The -T
option allows for the selection of multiple points by pressing the T or Insert keys in the running script for each relevant point. Complete the selection by pressing Enter. A marked entry appears underlined. Remove the marker by repeatedly pressing T or Delete.
The software uses the space as a field separator, unless you specify otherwise. However, the example shown in Listing 6 (Figure 6) uses a colon, which allows you to use tools (e.g., cut
) during further processing of the variable's contents, to address a column.
Menu Preselection
If you have no way to limit the list of menu options from the command in the pipe, filter the data when you call smenu
. If necessary, use regular expressions (-e
option, Listing 7). Alternatively, work with the positive hits (-i
option, Listing 8).
The effect is generally the same: The unwanted entries appear in a color that offer less contrast and cannot be selected (Figure 7). When using both options simultaneously, keep in mind that exclusion has a higher priority. As a result, you might not get any items to select.
PDF Search
To browse a (quite large) portfolio of PDF files, use the pdfsearch.sh
shell script (Listing 9). Using smenu, the small program displays the selection of hits and allows you to take further actions.
Listing 9
pdfsearch.sh
#!/bin/bash # pdfsearch.sh while true; do clear # Enter search term echo "browse PDF archive " echo "----------------------" read -p "enter search term (cancel: Enter or Ctrl+C): " sube if [ -z $sube ]; then exit fi # Evaluation list structure, case sensitivity is ignored. # only the number of hits is issued for i in $(pdfgrep -H -c -i "$sube" *.pdf); do number of hits = $(echo $i | cut-d\: -f2) if [ $number of hits-gt 0 ]; then hitlist=$(echo $hitlist $i) fi done # if hit is list empty, new loop run if [ -z "$hit list" ]; then echo "no hits" sleep 3 continue fi # here comes smenu while true; do file=$(echo $hitlist | tr "\ " "\n" | smenu -d -n20 -c -m "select file for display (q to cancel):" | cut -d\: -f1) # If cancel with [q], delete hit list and # new loop run if [ -z $file ]; then unset hit list break fi # Evince and Qpdfview support the transfer # a search term when launching on Shell evince --find "$sube" $file # continue or finished? Continue= $(echo "select done" | smenu -d -m "continue with" -s /A) if [ "$continue" = "done" ]; then break fi done done
The script only runs under Bash because it uses the read
command. Either assign the appropriate rights to run it directly, or call it with:
bash pdfsearch.sh
(For PDFs, check out qpdfview
or Evince: Both accept a search term at launch.)
When launching, enter the search term (Figure 8), which the script then transfers to pdfgrep
. It shows only the number of hits, ignoring case sensitivity. Any hits are provided for selection via smenu.
If you have selected a file to display, the script browses the search term in the PDF viewer. It then highlights it in the document (Figure 9). After closing the display program, either reuse the selection or enter a new search term (Figure 10).
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.