From 9021792c2f606f6dc3150765c4df2b4cfd426c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 23 Apr 2023 02:02:35 +0300 Subject: [PATCH] Script for Using Bookmarks (Separate URL and Name + Search with Keywords) This script allows us to open a bookmarked URL on the browser, only showing the name of the website, stripping the URL from the dmenu list. - If the URL has the word "search" in it, then the script will offer for a second dmenu for you to enter a keyword to search. - "searxng" entry, will offer for a second input after being chosen. Then you can enter a keyword to search from that website. It can be any website with search function. So look at your bookmarks --> choose "searxng" entry --> Write a keyword and enter --> Search for that keyword on searxng. - Otherwise it will open the website directly --> "cooking" entry can open "https://based.cooking" for example. - We rely on the JSON data formatting to separate URLS from the names we put on websites. So we need to program "jq". Summary: It first selects a website using dmenu, then checks if "search" is present in the URLQUERY such as "https://paulgo.io/search?q=". If "search" is present, it asks for keywords before opening the URL. If not, it directly opens the URL without asking for keywords. Execution Time: Instant Required Programs: jq | echo | grep | dunst | browser Required File: A bookmark file named ~/.local/share/larbs/urlquery formatted in JSON data format like this: Goes well with: The other script: bookmarkthis [ [ "searxng", "https://www.paulgo.io/search?q=" ], [ "cooking", "https://based.cooking" ] ] --- .local/bin/bookmarksearch | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .local/bin/bookmarksearch diff --git a/.local/bin/bookmarksearch b/.local/bin/bookmarksearch new file mode 100644 index 00000000..eab9a079 --- /dev/null +++ b/.local/bin/bookmarksearch @@ -0,0 +1,18 @@ +#!/bin/sh + +FILE="~/.local/share/larbs/urlquery" + +OBJ_SELECTED=$(jq -r ".[][0]" "$FILE" | dmenu -l 10 -p "Select a website") + +if [ -z "$OBJ_SELECTED" ]; then + exit 1 +fi + +URLQUERY=$(jq -r --arg sel "$OBJ_SELECTED" 'map(select(.[0] == $sel))[0][1]' "$FILE") + +if echo "$URLQUERY" | grep -q "search"; then + OBJ_KEYWORDS=$(dmenu -l 0 -p "Enter keywords" | tr " " "+") + firefox "${URLQUERY}${OBJ_KEYWORDS}" +else + firefox "${URLQUERY}" +fi