mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
This script allows us to bookmark websites as names instead of URLs.
It is useful with the other script: "bookmarksearch" that helps us use search engines on dmenu or directly open the site if the url doesn't include "search" word in it.
In this case the first entry would give us a second dmenu prompt to enter e keyword and the second entry will be opened directly when chosen:
[
"searxng",
"https://www.paulgo.io/search?q="
],
[
"cooking",
"https://based.cooking"
]
The script take the formatting and duplicate urls into account. You don't need to worry about it.
**Detailed Explanation:**
- We use a text file to store the URLs in: "~/.local/share/urlquery"
- The script uses the command "jq" to see a JSON data with specific information. We can use it to get the complete URL address or the name of the website.
- "grep" checks if the selected entry starts with "http". If it does, the script adds that URL with specific formatting inside the urlquery file after asking what should the URL be named.
- "jq" command again, considers the format of the file and adds a comma at the end followed by a new urlquery name and the address inside brackets and quotes in order to keep formatting correct.
- notify-send informs us about the output: If the URL is already on the list, or the selected entry is not an URL or when it is added successfully.
24 lines
705 B
Bash
24 lines
705 B
Bash
#!/bin/sh
|
|
|
|
FILE="~/.local/share/larbs/urlquery"
|
|
|
|
URL_FROM_CLIPBOARD=$(xclip -o)
|
|
|
|
if echo "$URL_FROM_CLIPBOARD" | grep -q "^http"; then
|
|
URL_ALREADY_EXISTS=$(jq --arg url "$URL_FROM_CLIPBOARD" 'map(.[1] == $url) | any' "$FILE")
|
|
|
|
if [ "$URL_ALREADY_EXISTS" = "true" ]; then
|
|
notify-send "The URL is already in the list."
|
|
exit 1
|
|
fi
|
|
|
|
URL_NAME=$(dmenu -l 0 -p "Enter a name for the URL")
|
|
|
|
if [ -n "$URL_NAME" ]; then
|
|
jq --arg name "$URL_NAME" --arg url "$URL_FROM_CLIPBOARD" '. += [[$name, $url]]' "$FILE" > "${FILE}.tmp" && mv "${FILE}.tmp" "$FILE" &&
|
|
notify-send "$URL_NAME is bookmarked."
|
|
fi
|
|
else
|
|
notify-send "The clipboard content is not a valid URL."
|
|
fi
|