From 943220f88471a680f28fb0508d246f02e6de25a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Mon, 24 Apr 2023 12:43:35 +0300 Subject: [PATCH 01/12] Extremely Improved Bookmarks (Search + Strip URL + More) The inspiration: (Luke Smith's Video): "Bookmarking for Unix Chads" Instructions & Justifications & Very Detailed Explanation for Everything can be found below. Short Summary - Allows users to manage and navigate bookmarks using dmenu. - The user can perform actions such as adding, deleting, and editing bookmarks. The script also handles searching within specific websites if the bookmarked URL has the word "search" in it. Such as the SearxNG Instance: "paulgo.io/search?q=". - One more interesting feature of it is that it modifies the order of bookmarks by their popularity (how frequently visited by you). - It can work with Dash and it has no bashisms. Execution Time: Instant Required Programs: dash (or bash) | jq | echo | grep | dmenu | notification daemon | browser | xclip (or "wl-paste" on Wayland) Instructions: These directories should exist: ~/.local/share/larbs/ 1. pacman -s jq (it's a very small program (I.E. 690kb) 2. Open a browser and highlight (xclip -o users) or copy (Wayland users) a website's URL (starting with "http") such as "https://github.com" 2. Run the script with a shortcut you created for the window manager that is used. 3. Write "@@" inside the terminal then enter (@@ can be changed of course). This opens the "Action Menu". 4. Select "Add a New Bookmark" option then enter. 5. The bookmark will be added inside the bookmarks menu. It can be edited or deleted later from the action menu that can be opened with "@@". 6. If a website that has the word "search" in it is added inside bookmarks such as a SearxNG instance "paulgo.io/search?q=" , its search function can be used. When selected, it will offer for a new prompt for the desired keywords. Justification: 1. The script uses jq for parsing and modifying JSON data, which is a lightweight and powerful command-line JSON processor. This choice allows for easy manipulation of the JSON file that stores bookmarks. 2. The use of the while loop with the dmenu interface ensures that the user can perform multiple actions (adding, deleting, or editing bookmarks) in a single session without needing to restart the script. 3. The script checks for an existing URLQUERY_FILE and initializes it with an empty JSON array "[]" if it doesn't exist or is empty. This ensures that the file is always in a valid state for the script to operate. 4. The script sorts bookmarks by popularity, allowing users to quickly access their most frequently visited bookmarks. This is achieved by incrementing a popularity value each time a bookmark is opened. 5. The script supports searching within specific websites by checking if the word "search" is in the URL (More words can be added). This feature provides a convenient way to search within bookmarked websites directly from the script. 6. The use of the dash shell (#!/bin/sh) as the interpreter provides a lightweight and fast shell environment for the script, improving performance. Since the script is efficient enough so this performance difference is not huge, so it can also be used with bash. Detailed Explanation 1. URLQUERY_FILE="~/.local/share/larbs/urlquery": Sets the path for the JSON file that will store the bookmarks. 2. The following block checks if the URLQUERY_FILE exists and if it's empty. If either condition is met, it initializes the file with an empty JSON array "[]". If there is no JSON array present, then no bookmark can be added. `if [ ! -f "$URLQUERY_FILE" ] || [ ! -s "$URLQUERY_FILE" ]; then echo "[]" > "$URLQUERY_FILE" fi` 3. ACTION_MENU='@@': Sets a special string for the action menu. 4. The read_bookmarks function reads the contents of the URLQUERY_FILE using jq. The write_bookmarks function writes the contents passed as an argument to a temporary file and then moves it to the URLQUERY_FILE. The update_bookmark_popularity function updates the popularity value of a bookmark, given its name. 5. The contains_search function checks if a given string contains the word "search". It returns 0 if it does, 1 otherwise. 6. bookmarks=$(read_bookmarks): Reads the bookmarks from the file and stores them in a variable. 7. touch "$URLQUERY_FILE": Ensures the URLQUERY_FILE exists by creating it if it doesn't. 8. The following while loop presents a menu to the user for choosing an action (Add, Delete, or Edit bookmark) or a bookmark to open. It continues until the user selects a bookmark to open or provides an empty input. `while true; do SELECTION=$(echo "$bookmarks" | jq -r '. | sort_by(.[2]) | reverse | .[] | .[0]' | rofi -dmenu -p "Bookmark") if [ -z "$SELECTION" ] || [ "$SELECTION" != "$ACTION_MENU" ]; then write_bookmarks "$bookmarks" break fi ACTION=$(echo "Add a New Bookmark\nDelete a Bookmark\nEdit a Bookmark" | rofi -dmenu -p "Action") #... done` 9. The case block inside the while loop performs the selected action (Add, Delete, or Edit) based on the user's input. 10. After the loop, the script checks if a valid bookmark is selected. If so, it updates the popularity value, writes the changes to the file, and opens the bookmark in Firefox or any browser. If the bookmark contains the word "search", it prompts the user for a search query before opening the URL in Firefox. 11. Creating and moving temporary files are for data integrity and safety. It ensures 0 file corruptions. Has no negative effect in terms of performance. --- .local/bin/chadmarked | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .local/bin/chadmarked diff --git a/.local/bin/chadmarked b/.local/bin/chadmarked new file mode 100644 index 00000000..414eac95 --- /dev/null +++ b/.local/bin/chadmarked @@ -0,0 +1,95 @@ +#!/bin/sh + +URLQUERY_FILE="~/.local/share/larbs/urlquery" +ACTION_MENU='@@' + +read_bookmarks() { + if [ ! -f "$URLQUERY_FILE" ] || [ ! -s "$URLQUERY_FILE" ]; then + echo "[]" + else + jq '.' "$URLQUERY_FILE" + fi +} + +write_bookmarks() { + echo "$1" > "${URLQUERY_FILE}.tmp" && mv "${URLQUERY_FILE}.tmp" "$URLQUERY_FILE" +} + +update_bookmark_popularity() { + jq --arg name "$1" '(.[] | select(.[0] == $name))[2] += 1' +} + +contains_search() { + case "$1" in + *"search"*) return 0 ;; + *) return 1 ;; + esac +} + +bookmarks=$(read_bookmarks) + + while true; do + SELECTION=$(echo "$bookmarks" | jq -r '. | sort_by(.[2]) | reverse | .[] | .[0]' | dmenu -l 10 -p "Bookmarks") + + if [ -z "$SELECTION" ] || [ "$SELECTION" != "$ACTION_MENU" ]; then + write_bookmarks "$bookmarks" + break + fi + + ACTION=$(echo "Add a New Bookmark\nDelete a Bookmark\nEdit a Bookmark" | dmenu -l 3 -p "Action") + + case "$ACTION" in + "Add a New Bookmark") + URL=$(xclip -o) + if echo "$URL" | grep -q "^http"; then + if ! echo "$bookmarks" | jq -e --arg url "$URL" '.[] | select(.[1] == $url)' > /dev/null; then + NAME=$(dmenu -l 0 -p "Name") + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg url "$URL" '. |= .+ [[ $name, $url, 0 ]]') + notify-send "'$NAME' is bookmarked." + else + notify-send "The URL is already in the list." + fi + else + notify-send "The clipboard content is not a valid URL." + fi + ;; + "Delete a Bookmark") + NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Delete") + if [ -n "$NAME" ]; then + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" 'del(.[] | select(.[0] == $name))') + notify-send "'$NAME' is deleted." + fi + ;; + "Edit a Bookmark") + NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Edit") + FIELD=$(echo "name\nURL" | dmenu -l 2 -p "Edit") + + if [ -n "$NAME" ] && [ -n "$FIELD" ]; then + NEW_VALUE=$(dmenu -l 0 -p "New $FIELD") + if [ "$FIELD" = "name" ]; then + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_name "$NEW_VALUE" '(.[] | select(.[0] == $name))[0] = $new_name') + else + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_url "$NEW_VALUE" '(.[] | select(.[0] == $name))[1] = $new_url') + fi + notify-send "'$NAME' is updated." + fi + ;; + esac +done + +if [ -n "$SELECTION" ] && [ "$SELECTION" != "$ACTION_MENU" ]; then + URL=$(echo "$bookmarks" | jq -r --arg name "$SELECTION" '.[] | select(.[0] == $name) | .[1]') + + if [ -z "$URL" ] || [ "$URL" = "null" ]; then + exit 0 + fi + + if contains_search "$URL"; then + QUERY=$(dmenu -l 0 -p "Search") + URL="${URL}${QUERY}" + fi + + bookmarks=$(echo "$bookmarks" | update_bookmark_popularity "$SELECTION") + write_bookmarks "$bookmarks" + $BROWSER "$URL" +fi From d3035edc7edba55bb7d42d51d23d7c9cf8edd403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sat, 9 Sep 2023 16:28:31 +0300 Subject: [PATCH 02/12] Simplify Further | Remove if statements 1- Used logical operators instead of if statements. 2- Improved indentations and blocks for better readibility. 3- Simplified in general. --- .local/bin/chadmarked | 92 ++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/.local/bin/chadmarked b/.local/bin/chadmarked index 414eac95..9ad07ae6 100644 --- a/.local/bin/chadmarked +++ b/.local/bin/chadmarked @@ -1,18 +1,15 @@ -#!/bin/sh +#!/bin/dash URLQUERY_FILE="~/.local/share/larbs/urlquery" ACTION_MENU='@@' read_bookmarks() { - if [ ! -f "$URLQUERY_FILE" ] || [ ! -s "$URLQUERY_FILE" ]; then - echo "[]" - else - jq '.' "$URLQUERY_FILE" - fi + [ -f "$URLQUERY_FILE" ] && [ -s "$URLQUERY_FILE" ] && jq '.' "$URLQUERY_FILE" || echo "[]" } write_bookmarks() { - echo "$1" > "${URLQUERY_FILE}.tmp" && mv "${URLQUERY_FILE}.tmp" "$URLQUERY_FILE" + echo "$1" > "${URLQUERY_FILE}.tmp" + mv "${URLQUERY_FILE}.tmp" "$URLQUERY_FILE" } update_bookmark_popularity() { @@ -22,74 +19,55 @@ update_bookmark_popularity() { contains_search() { case "$1" in *"search"*) return 0 ;; + *"wiki"*) return 0 ;; *) return 1 ;; esac } bookmarks=$(read_bookmarks) - while true; do - SELECTION=$(echo "$bookmarks" | jq -r '. | sort_by(.[2]) | reverse | .[] | .[0]' | dmenu -l 10 -p "Bookmarks") +while true; do + SELECTION=$(echo "$bookmarks" | jq -r '. | sort_by(.[2]) | reverse | .[] | .[0]' | dmenu -i -l 10 -p "Bookmarks") - if [ -z "$SELECTION" ] || [ "$SELECTION" != "$ACTION_MENU" ]; then - write_bookmarks "$bookmarks" - break - fi - - ACTION=$(echo "Add a New Bookmark\nDelete a Bookmark\nEdit a Bookmark" | dmenu -l 3 -p "Action") + [ -z "$SELECTION" ] || [ "$SELECTION" != "$ACTION_MENU" ] && write_bookmarks "$bookmarks" && break + ACTION=$(echo "Add a New Bookmark\nDelete a Bookmark\nEdit a Bookmark" | dmenu -i -l 3 -p "Action") case "$ACTION" in "Add a New Bookmark") URL=$(xclip -o) - if echo "$URL" | grep -q "^http"; then - if ! echo "$bookmarks" | jq -e --arg url "$URL" '.[] | select(.[1] == $url)' > /dev/null; then - NAME=$(dmenu -l 0 -p "Name") - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg url "$URL" '. |= .+ [[ $name, $url, 0 ]]') - notify-send "'$NAME' is bookmarked." - else - notify-send "The URL is already in the list." - fi - else - notify-send "The clipboard content is not a valid URL." - fi + echo "$URL" | grep -q "^http" && { + ! echo "$bookmarks" | jq -e --arg url "$URL" '.[] | select(.[1] == $url)' > /dev/null && { + NAME=$(dmenu -i -l 0 -p "Name") + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg url "$URL" '. |= .+ [[ $name, $url, 0 ]]') + notify-send "'$NAME' is bookmarked." + } || notify-send "The URL is already in the list." + } || notify-send "The clipboard content is not a valid URL." ;; "Delete a Bookmark") NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Delete") - if [ -n "$NAME" ]; then - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" 'del(.[] | select(.[0] == $name))') - notify-send "'$NAME' is deleted." - fi + [ -n "$NAME" ] && { + bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" 'del(.[] | select(.[0] == $name))') + notify-send "'$NAME' is deleted." + } ;; "Edit a Bookmark") NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Edit") - FIELD=$(echo "name\nURL" | dmenu -l 2 -p "Edit") - - if [ -n "$NAME" ] && [ -n "$FIELD" ]; then - NEW_VALUE=$(dmenu -l 0 -p "New $FIELD") - if [ "$FIELD" = "name" ]; then - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_name "$NEW_VALUE" '(.[] | select(.[0] == $name))[0] = $new_name') - else - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_url "$NEW_VALUE" '(.[] | select(.[0] == $name))[1] = $new_url') - fi - notify-send "'$NAME' is updated." - fi - ;; + FIELD=$(echo "name\nURL" | dmenu -i -l 2 -p "Edit") + [ -n "$NAME" ] && [ -n "$FIELD" ] && { + NEW_VALUE=$(dmenu -i -l 0 -p "New $FIELD") + [ "$FIELD" = "name" ] && bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_name "$NEW_VALUE" '(.[] | select(.[0] == $name))[0] = $new_name') || bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_url "$NEW_VALUE" '(.[] | select(.[0] == $name))[1] = $new_url') + notify-send "'$NAME' is updated." + } + ;; esac done -if [ -n "$SELECTION" ] && [ "$SELECTION" != "$ACTION_MENU" ]; then +[ -n "$SELECTION" ] && [ "$SELECTION" != "$ACTION_MENU" ] && { URL=$(echo "$bookmarks" | jq -r --arg name "$SELECTION" '.[] | select(.[0] == $name) | .[1]') - - if [ -z "$URL" ] || [ "$URL" = "null" ]; then - exit 0 - fi - - if contains_search "$URL"; then - QUERY=$(dmenu -l 0 -p "Search") - URL="${URL}${QUERY}" - fi - - bookmarks=$(echo "$bookmarks" | update_bookmark_popularity "$SELECTION") - write_bookmarks "$bookmarks" - $BROWSER "$URL" -fi + [ -z "$URL" ] || [ "$URL" = "null" ] || { + contains_search "$URL" && QUERY=$(dmenu -i -l 0 -p "Search") && URL="${URL}${QUERY}" + bookmarks=$(echo "$bookmarks" | update_bookmark_popularity "$SELECTION") + write_bookmarks "$bookmarks" + $BROWSER "$URL" + } +} From 4854a853e44fc949d68410ed221626a7ceb7cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Tue, 17 Oct 2023 11:32:19 +0300 Subject: [PATCH 03/12] simplify | improve | change jq to sed --- .local/bin/chadmarked | 158 ++++++++++++++++++++++++++---------------- 1 file changed, 98 insertions(+), 60 deletions(-) diff --git a/.local/bin/chadmarked b/.local/bin/chadmarked index 9ad07ae6..83da2d86 100644 --- a/.local/bin/chadmarked +++ b/.local/bin/chadmarked @@ -1,73 +1,111 @@ #!/bin/dash -URLQUERY_FILE="~/.local/share/larbs/urlquery" +URLQUERY_FILE="$HOME/.local/share/urlquery" +CLIPBOARD="xclip -o" ACTION_MENU='@@' -read_bookmarks() { - [ -f "$URLQUERY_FILE" ] && [ -s "$URLQUERY_FILE" ] && jq '.' "$URLQUERY_FILE" || echo "[]" +DMENU() { + dmenu -i -l $1 -p "$2" } -write_bookmarks() { - echo "$1" > "${URLQUERY_FILE}.tmp" - mv "${URLQUERY_FILE}.tmp" "$URLQUERY_FILE" +error_notify() { + notify-send "$1" + exit 1 } -update_bookmark_popularity() { - jq --arg name "$1" '(.[] | select(.[0] == $name))[2] += 1' +ensure_file_exists() { + [ -f "$URLQUERY_FILE" ] || { + notify-send "$URLQUERY_FILE does not exist. Creating it now." + touch "$URLQUERY_FILE" + } } -contains_search() { - case "$1" in - *"search"*) return 0 ;; - *"wiki"*) return 0 ;; - *) return 1 ;; - esac +get_selection() { + cut -d= -f1 "$URLQUERY_FILE" | DMENU $LINE_COUNT "Bookmarks" } -bookmarks=$(read_bookmarks) - -while true; do - SELECTION=$(echo "$bookmarks" | jq -r '. | sort_by(.[2]) | reverse | .[] | .[0]' | dmenu -i -l 10 -p "Bookmarks") - - [ -z "$SELECTION" ] || [ "$SELECTION" != "$ACTION_MENU" ] && write_bookmarks "$bookmarks" && break - - ACTION=$(echo "Add a New Bookmark\nDelete a Bookmark\nEdit a Bookmark" | dmenu -i -l 3 -p "Action") - case "$ACTION" in - "Add a New Bookmark") - URL=$(xclip -o) - echo "$URL" | grep -q "^http" && { - ! echo "$bookmarks" | jq -e --arg url "$URL" '.[] | select(.[1] == $url)' > /dev/null && { - NAME=$(dmenu -i -l 0 -p "Name") - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg url "$URL" '. |= .+ [[ $name, $url, 0 ]]') - notify-send "'$NAME' is bookmarked." - } || notify-send "The URL is already in the list." - } || notify-send "The clipboard content is not a valid URL." - ;; - "Delete a Bookmark") - NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Delete") - [ -n "$NAME" ] && { - bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" 'del(.[] | select(.[0] == $name))') - notify-send "'$NAME' is deleted." - } - ;; - "Edit a Bookmark") - NAME=$(echo "$bookmarks" | jq -r '.[] | .[0]' | dmenu -p "Edit") - FIELD=$(echo "name\nURL" | dmenu -i -l 2 -p "Edit") - [ -n "$NAME" ] && [ -n "$FIELD" ] && { - NEW_VALUE=$(dmenu -i -l 0 -p "New $FIELD") - [ "$FIELD" = "name" ] && bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_name "$NEW_VALUE" '(.[] | select(.[0] == $name))[0] = $new_name') || bookmarks=$(echo "$bookmarks" | jq --arg name "$NAME" --arg new_url "$NEW_VALUE" '(.[] | select(.[0] == $name))[1] = $new_url') - notify-send "'$NAME' is updated." - } - ;; - esac -done - -[ -n "$SELECTION" ] && [ "$SELECTION" != "$ACTION_MENU" ] && { - URL=$(echo "$bookmarks" | jq -r --arg name "$SELECTION" '.[] | select(.[0] == $name) | .[1]') - [ -z "$URL" ] || [ "$URL" = "null" ] || { - contains_search "$URL" && QUERY=$(dmenu -i -l 0 -p "Search") && URL="${URL}${QUERY}" - bookmarks=$(echo "$bookmarks" | update_bookmark_popularity "$SELECTION") - write_bookmarks "$bookmarks" - $BROWSER "$URL" - } +update_file() { + pattern="$1" + replacement="$2" + sed "/$pattern/c\\ +$replacement" "$URLQUERY_FILE" > "$URLQUERY_FILE.tmp" && mv "$URLQUERY_FILE.tmp" "$URLQUERY_FILE" || + error_notify "Failed to update the file." } + +is_valid_url() { + echo "$1" | grep -qE "^https?://[^[:space:]/?#][^[:space:]]+$" +} + +add_bookmark() { + URL=$($CLIPBOARD) + is_valid_url "$URL" || error_notify "The clipboard content is not a valid URL." + grep -q "=$URL$" "$URLQUERY_FILE" && notify-send "The URL is already in the list." && return + NAME=$(DMENU 0 "Name") + [ -n "$NAME" ] && echo "${NAME}=${URL}" >> "$URLQUERY_FILE" && notify-send "'$NAME' is bookmarked." +} + +delete_bookmark() { + NAME=$(get_selection) + [ -z "$NAME" ] && error_notify "Failed to delete the bookmark." + sed "/^$NAME=/d" "$URLQUERY_FILE" > "$URLQUERY_FILE.tmp" + mv "$URLQUERY_FILE.tmp" "$URLQUERY_FILE" + [ ! -s "$URLQUERY_FILE" ] || ! grep -qE "\S" "$URLQUERY_FILE" && rm "$URLQUERY_FILE" + notify-send "'$NAME' is deleted." +} + +edit_name() { + OLD_NAME="$1" + NEW_NAME=$(DMENU 0 "New Name") + [ -z "$NEW_NAME" ] && return + URL=$(grep "^$OLD_NAME=" "$URLQUERY_FILE" | cut -d= -f2) + update_file "^$OLD_NAME=" "$NEW_NAME=$URL" +} + +edit_url() { + NAME="$1" + NEW_URL=$(DMENU 0 "New URL") + [ -z "$NEW_URL" ] && return + update_file "^$NAME=.*" "$NAME=$NEW_URL" +} + +edit_bookmark() { + NAME=$(get_selection) + [ -z "$NAME" ] && error_notify "Failed to edit the bookmark." + FIELD=$(echo "Name\nURL" | DMENU 2 "Edit") + case "$FIELD" in + "Name") edit_name "$NAME" ;; + "URL") edit_url "$NAME" ;; + esac + notify-send "'$NAME' is updated." +} + +open_bookmark() { + URL=$(grep "^$SELECTION=" "$URLQUERY_FILE" | cut -d= -f2-) + case "$URL" in + *"search"*|*"wiki"*) + QUERY=$(DMENU 0 "Search") + URL="${URL}${QUERY}" + ;; + esac + $BROWSER "$URL" || notify-send "Failed to open the URL." +} + +ensure_file_exists + +LINE_COUNT=$(wc -l < "$URLQUERY_FILE") +SELECTION=$(get_selection) +[ -z "$SELECTION" ] && exit + +case "$SELECTION" in +"$ACTION_MENU") + ACTION=$(echo "Add\nDelete\nEdit" | DMENU 3 "Action") + case "$ACTION" in + "Add") add_bookmark ;; + "Delete") delete_bookmark ;; + "Edit") edit_bookmark ;; + esac + ;; +*) + open_bookmark + ;; +esac From 083da4d28c758968b7ad078f6ebe1ad08666c1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sat, 18 Nov 2023 22:54:40 +0300 Subject: [PATCH 04/12] Update chadmarked --- .local/bin/chadmarked | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.local/bin/chadmarked b/.local/bin/chadmarked index 83da2d86..00529483 100644 --- a/.local/bin/chadmarked +++ b/.local/bin/chadmarked @@ -46,7 +46,7 @@ add_bookmark() { delete_bookmark() { NAME=$(get_selection) - [ -z "$NAME" ] && error_notify "Failed to delete the bookmark." + [ -z "$NAME" ] && error_notify "Failed to delete the bookmark." && return sed "/^$NAME=/d" "$URLQUERY_FILE" > "$URLQUERY_FILE.tmp" mv "$URLQUERY_FILE.tmp" "$URLQUERY_FILE" [ ! -s "$URLQUERY_FILE" ] || ! grep -qE "\S" "$URLQUERY_FILE" && rm "$URLQUERY_FILE" @@ -70,7 +70,7 @@ edit_url() { edit_bookmark() { NAME=$(get_selection) - [ -z "$NAME" ] && error_notify "Failed to edit the bookmark." + [ -z "$NAME" ] && error_notify "Failed to edit the bookmark." && return FIELD=$(echo "Name\nURL" | DMENU 2 "Edit") case "$FIELD" in "Name") edit_name "$NAME" ;; @@ -93,6 +93,9 @@ open_bookmark() { ensure_file_exists LINE_COUNT=$(wc -l < "$URLQUERY_FILE") + +[ "$LINE_COUNT" -ge "15" ] && LINE_COUNT="15" + SELECTION=$(get_selection) [ -z "$SELECTION" ] && exit From f51d7451cb90a084fb3ed1fcac8ab0d12c00fefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sat, 18 Nov 2023 22:58:16 +0300 Subject: [PATCH 05/12] Make the name more intuitive. --- .local/bin/{chadmarked => bookmark_manager.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .local/bin/{chadmarked => bookmark_manager.sh} (100%) diff --git a/.local/bin/chadmarked b/.local/bin/bookmark_manager.sh similarity index 100% rename from .local/bin/chadmarked rename to .local/bin/bookmark_manager.sh From c9ad701e638dbb4fb2cff14c7bce120f4ab3d564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 01:10:01 +0300 Subject: [PATCH 06/12] Do not open random entries if not on the query --- .local/bin/bookmark_manager.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.local/bin/bookmark_manager.sh b/.local/bin/bookmark_manager.sh index 00529483..bee69e25 100644 --- a/.local/bin/bookmark_manager.sh +++ b/.local/bin/bookmark_manager.sh @@ -81,6 +81,7 @@ edit_bookmark() { open_bookmark() { URL=$(grep "^$SELECTION=" "$URLQUERY_FILE" | cut -d= -f2-) + [ -z "$URL" ] && notify-send "Bookmark not found." && exit 1 case "$URL" in *"search"*|*"wiki"*) QUERY=$(DMENU 0 "Search") From b71e0738ee078ad34ab5ae448a3ddf78bcde3bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 15:23:32 +0300 Subject: [PATCH 07/12] Update bookmark_manager.sh --- .local/bin/bookmark_manager.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.local/bin/bookmark_manager.sh b/.local/bin/bookmark_manager.sh index bee69e25..290ff4b4 100644 --- a/.local/bin/bookmark_manager.sh +++ b/.local/bin/bookmark_manager.sh @@ -40,7 +40,7 @@ add_bookmark() { URL=$($CLIPBOARD) is_valid_url "$URL" || error_notify "The clipboard content is not a valid URL." grep -q "=$URL$" "$URLQUERY_FILE" && notify-send "The URL is already in the list." && return - NAME=$(DMENU 0 "Name") + NAME=$(echo "" | DMENU 0 "Name") [ -n "$NAME" ] && echo "${NAME}=${URL}" >> "$URLQUERY_FILE" && notify-send "'$NAME' is bookmarked." } @@ -55,7 +55,7 @@ delete_bookmark() { edit_name() { OLD_NAME="$1" - NEW_NAME=$(DMENU 0 "New Name") + NEW_NAME=$(echo "" | DMENU 0 "New Name") [ -z "$NEW_NAME" ] && return URL=$(grep "^$OLD_NAME=" "$URLQUERY_FILE" | cut -d= -f2) update_file "^$OLD_NAME=" "$NEW_NAME=$URL" @@ -63,7 +63,7 @@ edit_name() { edit_url() { NAME="$1" - NEW_URL=$(DMENU 0 "New URL") + NEW_URL=$(echo "" | DMENU 0 "New URL") [ -z "$NEW_URL" ] && return update_file "^$NAME=.*" "$NAME=$NEW_URL" } @@ -84,7 +84,7 @@ open_bookmark() { [ -z "$URL" ] && notify-send "Bookmark not found." && exit 1 case "$URL" in *"search"*|*"wiki"*) - QUERY=$(DMENU 0 "Search") + QUERY=$(echo "" | DMENU 0 "Search") URL="${URL}${QUERY}" ;; esac From 36add3ec999fa746924f9eff63945c81a450facd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 15:30:07 +0300 Subject: [PATCH 08/12] Rename bookmark_manager.sh to browser_bookmarks.sh --- .local/bin/{bookmark_manager.sh => browser_bookmarks.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .local/bin/{bookmark_manager.sh => browser_bookmarks.sh} (100%) diff --git a/.local/bin/bookmark_manager.sh b/.local/bin/browser_bookmarks.sh similarity index 100% rename from .local/bin/bookmark_manager.sh rename to .local/bin/browser_bookmarks.sh From 2a5cf351428826fe4d2c4872f9f70dbb979f935d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 18:51:54 +0300 Subject: [PATCH 09/12] Add some comments and an example URL --- .local/bin/browser_bookmarks.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.local/bin/browser_bookmarks.sh b/.local/bin/browser_bookmarks.sh index 290ff4b4..38d154df 100644 --- a/.local/bin/browser_bookmarks.sh +++ b/.local/bin/browser_bookmarks.sh @@ -4,6 +4,9 @@ URLQUERY_FILE="$HOME/.local/share/urlquery" CLIPBOARD="xclip -o" ACTION_MENU='@@' +# For additional search function, add keywords under open_bookmark function's +# case condition next to search and wiki keywords. + DMENU() { dmenu -i -l $1 -p "$2" } @@ -16,7 +19,7 @@ error_notify() { ensure_file_exists() { [ -f "$URLQUERY_FILE" ] || { notify-send "$URLQUERY_FILE does not exist. Creating it now." - touch "$URLQUERY_FILE" + echo "SearXNG=https://searx.tiekoetter.com/search?q=" > "$URLQUERY_FILE" } } @@ -83,7 +86,7 @@ open_bookmark() { URL=$(grep "^$SELECTION=" "$URLQUERY_FILE" | cut -d= -f2-) [ -z "$URL" ] && notify-send "Bookmark not found." && exit 1 case "$URL" in - *"search"*|*"wiki"*) + *"search"*|*"wiki"*|*"packages"*) QUERY=$(echo "" | DMENU 0 "Search") URL="${URL}${QUERY}" ;; From 56304e551d578a28dcc3df57c5cd88e5e15f2417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 19:17:29 +0300 Subject: [PATCH 10/12] Improve comments. --- .local/bin/browser_bookmarks.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.local/bin/browser_bookmarks.sh b/.local/bin/browser_bookmarks.sh index 38d154df..3cc3c47f 100644 --- a/.local/bin/browser_bookmarks.sh +++ b/.local/bin/browser_bookmarks.sh @@ -4,8 +4,7 @@ URLQUERY_FILE="$HOME/.local/share/urlquery" CLIPBOARD="xclip -o" ACTION_MENU='@@' -# For additional search function, add keywords under open_bookmark function's -# case condition next to search and wiki keywords. +# For additional search function, see information on open_bookmark function below DMENU() { dmenu -i -l $1 -p "$2" @@ -86,7 +85,7 @@ open_bookmark() { URL=$(grep "^$SELECTION=" "$URLQUERY_FILE" | cut -d= -f2-) [ -z "$URL" ] && notify-send "Bookmark not found." && exit 1 case "$URL" in - *"search"*|*"wiki"*|*"packages"*) + *"search"*|*"wiki"*|*"packages"*) # Add your additional search keywords here similarly. QUERY=$(echo "" | DMENU 0 "Search") URL="${URL}${QUERY}" ;; From 5fb8b6ca906dac6cd51ab71729a95ce676e8e3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Fri, 5 Jan 2024 13:26:36 +0300 Subject: [PATCH 11/12] use best practices for variables and formatting --- .local/bin/browser_bookmarks.sh | 145 ++++++++++++++++---------------- 1 file changed, 74 insertions(+), 71 deletions(-) diff --git a/.local/bin/browser_bookmarks.sh b/.local/bin/browser_bookmarks.sh index 3cc3c47f..1199ecb6 100644 --- a/.local/bin/browser_bookmarks.sh +++ b/.local/bin/browser_bookmarks.sh @@ -1,117 +1,120 @@ #!/bin/dash -URLQUERY_FILE="$HOME/.local/share/urlquery" -CLIPBOARD="xclip -o" -ACTION_MENU='@@' +URLQUERY_FILE="${HOME}/.local/share/urlquery" +ACTION_MENU="@@" -# For additional search function, see information on open_bookmark function below +# For additional search function, see information on open_bookmark function below + +CLIPBOARD() { + xclip -o +} DMENU() { - dmenu -i -l $1 -p "$2" + dmenu -i -l "${1}" -p "${2}" } error_notify() { - notify-send "$1" - exit 1 + notify-send "${1}" + exit "1" } ensure_file_exists() { - [ -f "$URLQUERY_FILE" ] || { - notify-send "$URLQUERY_FILE does not exist. Creating it now." - echo "SearXNG=https://searx.tiekoetter.com/search?q=" > "$URLQUERY_FILE" - } + [ -f "${URLQUERY_FILE}" ] || { + notify-send "${URLQUERY_FILE} does not exist. Creating it now." + echo "SearXNG=https://searx.tiekoetter.com/search?q=" > "${URLQUERY_FILE}" + } } get_selection() { - cut -d= -f1 "$URLQUERY_FILE" | DMENU $LINE_COUNT "Bookmarks" + cut -d= -f1 "${URLQUERY_FILE}" | DMENU "${LINE_COUNT}" "Bookmarks" } update_file() { - pattern="$1" - replacement="$2" - sed "/$pattern/c\\ -$replacement" "$URLQUERY_FILE" > "$URLQUERY_FILE.tmp" && mv "$URLQUERY_FILE.tmp" "$URLQUERY_FILE" || - error_notify "Failed to update the file." + pattern="${1}" + replacement="${2}" + sed "/${pattern}/c\\ +${replacement}" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" && mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" || + error_notify "Failed to update the file." } is_valid_url() { - echo "$1" | grep -qE "^https?://[^[:space:]/?#][^[:space:]]+$" + echo "${1}" | grep -qE "^https?://[^[:space:]/?#][^[:space:]]+$" } add_bookmark() { - URL=$($CLIPBOARD) - is_valid_url "$URL" || error_notify "The clipboard content is not a valid URL." - grep -q "=$URL$" "$URLQUERY_FILE" && notify-send "The URL is already in the list." && return - NAME=$(echo "" | DMENU 0 "Name") - [ -n "$NAME" ] && echo "${NAME}=${URL}" >> "$URLQUERY_FILE" && notify-send "'$NAME' is bookmarked." + URL="$(CLIPBOARD)" + is_valid_url "${URL}" || error_notify "The clipboard content is not a valid URL." + grep -q "=${URL}$" "${URLQUERY_FILE}" && notify-send "The URL is already in the list." && return + NAME="$(echo "" | DMENU "0" "Name")" + [ -n "${NAME}" ] && echo "${NAME}=${URL}" >> "${URLQUERY_FILE}" && notify-send "'${NAME}' is bookmarked." } delete_bookmark() { - NAME=$(get_selection) - [ -z "$NAME" ] && error_notify "Failed to delete the bookmark." && return - sed "/^$NAME=/d" "$URLQUERY_FILE" > "$URLQUERY_FILE.tmp" - mv "$URLQUERY_FILE.tmp" "$URLQUERY_FILE" - [ ! -s "$URLQUERY_FILE" ] || ! grep -qE "\S" "$URLQUERY_FILE" && rm "$URLQUERY_FILE" - notify-send "'$NAME' is deleted." + NAME="$(get_selection)" + [ -z "${NAME}" ] && error_notify "Failed to delete the bookmark." && return + sed "/^${NAME}=/d" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" + mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" + [ ! -s "${URLQUERY_FILE}" ] || ! grep -qE "\S" "${URLQUERY_FILE}" && rm "${URLQUERY_FILE}" + notify-send "'${NAME}' is deleted." } edit_name() { - OLD_NAME="$1" - NEW_NAME=$(echo "" | DMENU 0 "New Name") - [ -z "$NEW_NAME" ] && return - URL=$(grep "^$OLD_NAME=" "$URLQUERY_FILE" | cut -d= -f2) - update_file "^$OLD_NAME=" "$NEW_NAME=$URL" + OLD_NAME="${1}" + NEW_NAME="$(echo "" | DMENU "0" "New Name")" + [ -z "${NEW_NAME}" ] && return + URL="$(grep "^${OLD_NAME}=" "${URLQUERY_FILE}" | cut -d= -f2)" + update_file "^${OLD_NAME}=" "${NEW_NAME}=${URL}" } edit_url() { - NAME="$1" - NEW_URL=$(echo "" | DMENU 0 "New URL") - [ -z "$NEW_URL" ] && return - update_file "^$NAME=.*" "$NAME=$NEW_URL" + NAME="${1}" + NEW_URL="$(echo "" | DMENU "0" "New URL")" + [ -z "${NEW_URL}" ] && return + update_file "^${NAME}=.*" "${NAME}=${NEW_URL}" } edit_bookmark() { - NAME=$(get_selection) - [ -z "$NAME" ] && error_notify "Failed to edit the bookmark." && return - FIELD=$(echo "Name\nURL" | DMENU 2 "Edit") - case "$FIELD" in - "Name") edit_name "$NAME" ;; - "URL") edit_url "$NAME" ;; - esac - notify-send "'$NAME' is updated." + NAME="$(get_selection)" + [ -z "${NAME}" ] && error_notify "Failed to edit the bookmark." && return + FIELD="$(echo "Name\nURL" | DMENU "2" "Edit")" + case "${FIELD}" in + "Name") edit_name "${NAME}" ;; + "URL") edit_url "${NAME}" ;; + esac + notify-send "'${NAME}' is updated." } open_bookmark() { - URL=$(grep "^$SELECTION=" "$URLQUERY_FILE" | cut -d= -f2-) - [ -z "$URL" ] && notify-send "Bookmark not found." && exit 1 - case "$URL" in - *"search"*|*"wiki"*|*"packages"*) # Add your additional search keywords here similarly. - QUERY=$(echo "" | DMENU 0 "Search") - URL="${URL}${QUERY}" - ;; - esac - $BROWSER "$URL" || notify-send "Failed to open the URL." + URL="$(grep "^${SELECTION}=" "${URLQUERY_FILE}" | cut -d= -f2-)" + [ -z "${URL}" ] && notify-send "Bookmark not found." && exit "1" + case "${URL}" in + *"search"* | *"wiki"* | *"packages"*) # Add your additional search keywords here similarly. + QUERY="$(echo "" | DMENU "0" "Search")" + URL="${URL}${QUERY}" + ;; + esac + "${BROWSER}" "${URL}" || notify-send "Failed to open the URL." } ensure_file_exists -LINE_COUNT=$(wc -l < "$URLQUERY_FILE") +LINE_COUNT="$(wc -l < "${URLQUERY_FILE}")" -[ "$LINE_COUNT" -ge "15" ] && LINE_COUNT="15" +[ "${LINE_COUNT}" -ge "15" ] && LINE_COUNT="15" -SELECTION=$(get_selection) -[ -z "$SELECTION" ] && exit +SELECTION="$(get_selection)" +[ -z "${SELECTION}" ] && exit -case "$SELECTION" in -"$ACTION_MENU") - ACTION=$(echo "Add\nDelete\nEdit" | DMENU 3 "Action") - case "$ACTION" in - "Add") add_bookmark ;; - "Delete") delete_bookmark ;; - "Edit") edit_bookmark ;; - esac - ;; -*) - open_bookmark - ;; +case "${SELECTION}" in + "${ACTION_MENU}") + ACTION="$(echo "Add\nDelete\nEdit" | DMENU "3" "Action")" + case "${ACTION}" in + "Add") add_bookmark ;; + "Delete") delete_bookmark ;; + "Edit") edit_bookmark ;; + esac + ;; + *) + open_bookmark + ;; esac From 0eaff5c245ccbbb0320dcdae06c778188774b0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 7 Jan 2024 09:59:57 +0300 Subject: [PATCH 12/12] Use new lines & empty lines for readability --- .local/bin/browser_bookmarks.sh | 132 +++++++++++++++++++------------- 1 file changed, 78 insertions(+), 54 deletions(-) diff --git a/.local/bin/browser_bookmarks.sh b/.local/bin/browser_bookmarks.sh index 1199ecb6..5710c49e 100644 --- a/.local/bin/browser_bookmarks.sh +++ b/.local/bin/browser_bookmarks.sh @@ -6,94 +6,116 @@ ACTION_MENU="@@" # For additional search function, see information on open_bookmark function below CLIPBOARD() { - xclip -o + xclip -o } DMENU() { - dmenu -i -l "${1}" -p "${2}" + dmenu -i -l "${1}" -p "${2}" } error_notify() { - notify-send "${1}" - exit "1" + notify-send "${1}" + exit "1" } ensure_file_exists() { - [ -f "${URLQUERY_FILE}" ] || { - notify-send "${URLQUERY_FILE} does not exist. Creating it now." - echo "SearXNG=https://searx.tiekoetter.com/search?q=" > "${URLQUERY_FILE}" - } + [ -f "${URLQUERY_FILE}" ] || { + notify-send "${URLQUERY_FILE} does not exist. Creating it now." + printf "SearXNG=https://searx.tiekoetter.com/search?q=\n" > "${URLQUERY_FILE}" + } } get_selection() { - cut -d= -f1 "${URLQUERY_FILE}" | DMENU "${LINE_COUNT}" "Bookmarks" + cut -d= -f1 "${URLQUERY_FILE}" | DMENU "${LINE_COUNT}" "Bookmarks" } update_file() { - pattern="${1}" - replacement="${2}" - sed "/${pattern}/c\\ -${replacement}" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" && mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" || - error_notify "Failed to update the file." + pattern="${1}" + replacement="${2}" + + sed "/${pattern}/c\\${replacement}" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" && + mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" || + error_notify "Failed to update the file." } is_valid_url() { - echo "${1}" | grep -qE "^https?://[^[:space:]/?#][^[:space:]]+$" + printf "%s\n" "${1}" | grep -qE "^https?://[^[:space:]/?#][^[:space:]]+$" } add_bookmark() { - URL="$(CLIPBOARD)" - is_valid_url "${URL}" || error_notify "The clipboard content is not a valid URL." - grep -q "=${URL}$" "${URLQUERY_FILE}" && notify-send "The URL is already in the list." && return - NAME="$(echo "" | DMENU "0" "Name")" - [ -n "${NAME}" ] && echo "${NAME}=${URL}" >> "${URLQUERY_FILE}" && notify-send "'${NAME}' is bookmarked." + URL="$(CLIPBOARD)" + + is_valid_url "${URL}" || error_notify "The clipboard content is not a valid URL." + + grep -q "=${URL}$" "${URLQUERY_FILE}" && + notify-send "The URL is already in the list." && return + + NAME="$(printf "" | DMENU "0" "Name")" + + [ -n "${NAME}" ] && printf "%s\n" "${NAME}=${URL}" >> "${URLQUERY_FILE}" && + notify-send "'${NAME}' is bookmarked." } delete_bookmark() { - NAME="$(get_selection)" - [ -z "${NAME}" ] && error_notify "Failed to delete the bookmark." && return - sed "/^${NAME}=/d" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" - mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" - [ ! -s "${URLQUERY_FILE}" ] || ! grep -qE "\S" "${URLQUERY_FILE}" && rm "${URLQUERY_FILE}" - notify-send "'${NAME}' is deleted." + NAME="$(get_selection)" + + [ -z "${NAME}" ] && error_notify "Failed to delete the bookmark." && return + + sed "/^${NAME}=/d" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" + mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" + + [ -s "${URLQUERY_FILE}" ] && grep -qE "\S" "${URLQUERY_FILE}" || rm "${URLQUERY_FILE}" + + notify-send "'${NAME}' is deleted." } edit_name() { - OLD_NAME="${1}" - NEW_NAME="$(echo "" | DMENU "0" "New Name")" - [ -z "${NEW_NAME}" ] && return - URL="$(grep "^${OLD_NAME}=" "${URLQUERY_FILE}" | cut -d= -f2)" - update_file "^${OLD_NAME}=" "${NEW_NAME}=${URL}" + OLD_NAME="${1}" + NEW_NAME="$(printf "" | DMENU "0" "New Name")" + + [ -z "${NEW_NAME}" ] && return + + URL="$(grep "^${OLD_NAME}=" "${URLQUERY_FILE}" | cut -d= -f2)" + + update_file "^${OLD_NAME}=" "${NEW_NAME}=${URL}" } edit_url() { - NAME="${1}" - NEW_URL="$(echo "" | DMENU "0" "New URL")" - [ -z "${NEW_URL}" ] && return - update_file "^${NAME}=.*" "${NAME}=${NEW_URL}" + NAME="${1}" + NEW_URL="$(echo "" | DMENU "0" "New URL")" + + [ -z "${NEW_URL}" ] && return + + update_file "^${NAME}=.*" "${NAME}=${NEW_URL}" } edit_bookmark() { - NAME="$(get_selection)" - [ -z "${NAME}" ] && error_notify "Failed to edit the bookmark." && return - FIELD="$(echo "Name\nURL" | DMENU "2" "Edit")" - case "${FIELD}" in - "Name") edit_name "${NAME}" ;; - "URL") edit_url "${NAME}" ;; - esac - notify-send "'${NAME}' is updated." + NAME="$(get_selection)" + + [ -z "${NAME}" ] && error_notify "Failed to edit the bookmark." && return + + FIELD="$(printf "Name\nURL\n" | DMENU "2" "Edit")" + + case "${FIELD}" in + "Name")edit_name "${NAME}";; + "URL")edit_url "${NAME}" + esac + + notify-send "'${NAME}' is updated." } open_bookmark() { - URL="$(grep "^${SELECTION}=" "${URLQUERY_FILE}" | cut -d= -f2-)" - [ -z "${URL}" ] && notify-send "Bookmark not found." && exit "1" - case "${URL}" in - *"search"* | *"wiki"* | *"packages"*) # Add your additional search keywords here similarly. - QUERY="$(echo "" | DMENU "0" "Search")" - URL="${URL}${QUERY}" - ;; - esac - "${BROWSER}" "${URL}" || notify-send "Failed to open the URL." + URL="$(grep "^${SELECTION}=" "${URLQUERY_FILE}" | cut -d= -f2-)" + + [ -z "${URL}" ] && notify-send "Bookmark not found." && exit "1" + + case "${URL}" in + *"search"* | *"wiki"* | *"packages"*) QUERY="$(echo "" | DMENU "0" "Search")" + URL="${URL}${QUERY}" + ;; + esac + + "${BROWSER}" "${URL}" || notify-send "Failed to open the URL." } ensure_file_exists @@ -103,12 +125,14 @@ LINE_COUNT="$(wc -l < "${URLQUERY_FILE}")" [ "${LINE_COUNT}" -ge "15" ] && LINE_COUNT="15" SELECTION="$(get_selection)" + [ -z "${SELECTION}" ] && exit case "${SELECTION}" in "${ACTION_MENU}") - ACTION="$(echo "Add\nDelete\nEdit" | DMENU "3" "Action")" - case "${ACTION}" in + ACTION="$(printf "Add\nDelete\nEdit\n" | DMENU "3" "Action")" + + case "${ACTION}" in "Add") add_bookmark ;; "Delete") delete_bookmark ;; "Edit") edit_bookmark ;;