Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extremely Improved Bookmarks (Search + Strip URL + More) #1312

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Commits on Apr 24, 2023

  1. 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.
    emrakyz authored Apr 24, 2023
    Configuration menu
    Copy the full SHA
    943220f View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2023

  1. 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.
    emrakyz authored Sep 9, 2023
    Configuration menu
    Copy the full SHA
    d3035ed View commit details
    Browse the repository at this point in the history

Commits on Oct 17, 2023

  1. Configuration menu
    Copy the full SHA
    4854a85 View commit details
    Browse the repository at this point in the history

Commits on Nov 18, 2023

  1. Update chadmarked

    emrakyz authored Nov 18, 2023
    Configuration menu
    Copy the full SHA
    083da4d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f51d745 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    c9ad701 View commit details
    Browse the repository at this point in the history

Commits on Nov 19, 2023

  1. Update bookmark_manager.sh

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    b71e073 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    36add3e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    2a5cf35 View commit details
    Browse the repository at this point in the history
  4. Improve comments.

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    56304e5 View commit details
    Browse the repository at this point in the history

Commits on Jan 5, 2024

  1. Configuration menu
    Copy the full SHA
    5fb8b6c View commit details
    Browse the repository at this point in the history

Commits on Jan 7, 2024

  1. Configuration menu
    Copy the full SHA
    0eaff5c View commit details
    Browse the repository at this point in the history

Commits on Jun 30, 2024

  1. Configuration menu
    Copy the full SHA
    fe2747d View commit details
    Browse the repository at this point in the history
  2. Small clean-up

    emrakyz authored Jun 30, 2024
    Configuration menu
    Copy the full SHA
    7d74a86 View commit details
    Browse the repository at this point in the history
  3. Decrease lines

    emrakyz authored Jun 30, 2024
    Configuration menu
    Copy the full SHA
    635ac64 View commit details
    Browse the repository at this point in the history
  4. Decrease 3 more lines

    emrakyz authored Jun 30, 2024
    Configuration menu
    Copy the full SHA
    787ae2c View commit details
    Browse the repository at this point in the history