summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/.bin/add-bookmark.sh36
-rwxr-xr-xbin/.bin/open-bookmark.sh23
2 files changed, 59 insertions, 0 deletions
diff --git a/bin/.bin/add-bookmark.sh b/bin/.bin/add-bookmark.sh
new file mode 100755
index 0000000..9a8ab6b
--- /dev/null
+++ b/bin/.bin/add-bookmark.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BOOKMARKS_FILE="$DOTFILES_REPO/bookmarks.txt"
+
+mkdir -p "$(dirname "$BOOKMARKS_FILE")"
+touch "$BOOKMARKS_FILE"
+
+xdotool key --delay 50 ctrl+l ctrl+c Escape
+
+sleep 0.15
+
+URL=$(xclip -selection clipboard -o)
+
+if [[ "$URL" =~ ^https?:// ]]; then
+ NAME=$(zenity --entry \
+ --title="Add Bookmark" \
+ --text="Enter a name for this bookmark:" \
+ --entry-text="" 2>/dev/null)
+
+ if [ -z "$NAME" ]; then
+ notify-send "Bookmark Cancelled" "No name was provided."
+ exit 0
+ fi
+
+ CLEAN_NAME=$(echo "$NAME" | tr '|' '-')
+
+ if ! grep -q "|$URL$" "$BOOKMARKS_FILE"; then
+ echo "$CLEAN_NAME|$URL" >>"$BOOKMARKS_FILE"
+ notify-send "Bookmark Saved" "$CLEAN_NAME\n$URL"
+ else
+ notify-send "Bookmark" "This exact URL already exists!"
+ fi
+else
+ notify-send "Bookmark Error" "Clipboard did not contain a valid URL."
+fi
diff --git a/bin/.bin/open-bookmark.sh b/bin/.bin/open-bookmark.sh
new file mode 100755
index 0000000..67e724b
--- /dev/null
+++ b/bin/.bin/open-bookmark.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BOOKMARKS_FILE="$DOTFILES_REPO/bookmarks.txt"
+
+if [ ! -f "$BOOKMARKS_FILE" ] || [ ! -s "$BOOKMARKS_FILE" ]; then
+ notify-send "Bookmarks" "Your bookmarks file is empty or missing."
+ exit 1
+fi
+
+SELECTION=$(cut -d'|' -f1 "$BOOKMARKS_FILE" | rofi -dmenu -p "Go To:")
+
+if [ -z "$SELECTION" ]; then
+ exit 0
+fi
+
+URL=$(grep "^$SELECTION|" "$BOOKMARKS_FILE" | head -n 1 | cut -d'|' -f2)
+
+if [ -n "$URL" ]; then
+ firefox "$URL" &
+else
+ notify-send "Error" "Could not resolve the URL for: $SELECTION"
+fi