summaryrefslogtreecommitdiff
path: root/bookmark
diff options
context:
space:
mode:
authorBlake Romero <blake@blkrom.com>2024-11-09 00:18:33 +0000
committerBlake Romero <blake@blkrom.com>2024-11-09 00:18:33 +0000
commita7c24654af07247ab7fffd8199ed1eaf25df31be (patch)
tree870ef227ceaf9aa90ab1e18c31871d3dacb4c214 /bookmark
parent51a653139e10b0549ddc6553a17a835877ba196a (diff)
Add bookmark script
Diffstat (limited to 'bookmark')
-rwxr-xr-xbookmark73
1 files changed, 73 insertions, 0 deletions
diff --git a/bookmark b/bookmark
new file mode 100755
index 0000000..938eb04
--- /dev/null
+++ b/bookmark
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+#
+# BOOKMARK
+#
+
+bookmarks="$HOME/documents/bookmarks"
+browser=librewolf
+
+# Add a bookmark
+if [ "$1" = "add" ]; then
+
+ # Get URL from browser
+ wlrctl window focus $browser || exit 1
+ wtype -M ctrl l -m ctrl
+ wtype -M ctrl c -m ctrl
+ sleep 0.5
+ link=$(wl-paste --primary)
+
+ # Check if bookmark exists
+ if grep "$link" "$bookmarks"; then
+ notify-send "Bookmark already exists!"
+ exit 1
+ fi
+
+ # Prompt for link confirmation
+ addbookmark=$(printf "Yes\nNo" | bemenu -p "Add '$link' to bookmarks?" --auto-select)
+
+ if [ "$addbookmark" = "Yes" ]; then
+ description=$(curl -L "$link" | sed -n '/<title>/p' | sed -E 's,<title>(.*)</title>,\1,' | xargs)
+
+ [ -z "$description" ] \
+ && description=$(: | bemenu -p "Enter a description: ")
+
+ # Prompt for description confirmation
+ usedescription=$(printf "Yes\nNo" | bemenu -p "Use description '$description'?" --auto-select)
+ [ -z "$usedescription" ] && exit 1
+
+ if [ "$usedescription" = "No" ]; then
+ description=$(: | bemenu -p "Enter a description: ")
+ fi
+
+ printf "# %s\n%s\n" "$description" "$link" >> "$bookmarks" \
+ && notify-send "Bookmark Added" "$link"
+ fi
+
+ exit
+
+fi
+
+# Get Bookmark info
+description=$(sed 's/# //' "$bookmarks" | sed -n 'p;n' | bemenu -p 'Select a Bookmark')
+[ -z "$description" ] && exit 1
+link=$(sed -n "/^# $description$/{n;p}" "$bookmarks")
+
+# Perform an action on a bookmark
+case "$(printf 'Open\nCopy\nType' | bemenu -p 'Bookmark action')" in
+ "Open")
+ wlrctl window focus $browser
+ "$browser" "$link"
+ ;;
+ "Copy")
+ wl-copy -on "$link"
+ notify-send "Bookmark Copied" "$description"
+ ;;
+ "Type")
+ echo "$link" | wtype -
+ ;;
+ *)
+ exit
+ ;;
+esac
+