From 791671a31cc1f42b3f80e0ebb07db1c28bd1a01a Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 16 Apr 2025 18:07:05 +0100 Subject: [PATCH] [qutebrowser_dmenu.pl]: Add qutebrowser_dmenu.pl --- README.md | 1 + src/qutebrowser_dmenu.pl | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 src/qutebrowser_dmenu.pl diff --git a/README.md b/README.md index 11ebc0f..7d047f7 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - `music_dmenu.sh`: script to play a specific artist, album, or track selected with dmenu. - `play_music.sh`: simple script to play music albums based off the supplied artist & album name. - `qutebrowser_search.sh`: script that finds all the search engines defined in the qutebrowser `config.py` configuration file and makes them available for searching via dmenu, i.e. allow web searching with qutebrowser without having to wait for it to start up before you start your search. + - `qutebrowser_dmenu.pl`: script that constructs a `dmenu` menu of all search engines defined in the `qutebrowser` configuration file for searching without first launching `qutebrowser`. - `repos_checker.sh`: script to find all of the Git repositories in the current directory & its sub-directories and display each found repository's `git status`. - `screenshot.sh`: screenshot script for both Xorg and Wayland with selection that both saves the image file and adds the image to the clipboard, and notifies the user via `notify-send`. - `stdin_to_notis.sh`: scripts that reads from `stdin` and sends each line as a system notification. Intended for use when a program that outputs to `stdout` is called from a non-terminal or graphical program, making the `stdout` output inaccessible. The output can instead be piped into this script to make it readable as a system notification. diff --git a/src/qutebrowser_dmenu.pl b/src/qutebrowser_dmenu.pl new file mode 100755 index 0000000..1e8d8ac --- /dev/null +++ b/src/qutebrowser_dmenu.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -l +# Script that constructs a `dmenu` menu of all search engines defined in the qutebrowser configuration file for searching without first launching qutebrowser +use strict; +use warnings; + +my $file_path = "$ENV{HOME}/.config/qutebrowser/config.py"; +my @search_engines; + +open(my $file_handler, '<', $file_path) or die("Couldn't open $file_path $!"); +my $inside = 0; + +while (my $line = <$file_handler>) { + + if ($line =~ /^c\.url\.searchengines\s*=\s*{/) { + $inside = 1; + next; + } + + if ($inside) { + last if ($line =~ /^\s*}/); + + $line =~ s/["':]//g; + $line =~ s/^\s+|\s+$//g; + + my ($search_engine) = split(/\s+/, $line); + + if ($search_engine && $search_engine !~ /^\s*#/) { + push(@search_engines, $search_engine); + } + } +} + +close($file_handler); + +my $dmenu_input = join("\n", @search_engines); +my $selection = `echo "$dmenu_input" | dmenu`; + +if ($selection) { + exec("qutebrowser", $selection); +}