summaryrefslogtreecommitdiff
path: root/bookmark
blob: db8800d0d5a872e16b7ae391ec9c7d6a63306406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/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)

	# Description
	if [ "$addbookmark" = "Yes" ]; then
		description=$(: | bemenu -p "Enter a description: ")
		[ -z "$description" ] && exit 1

		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")
[ -z "$link" ] && exit 1

# Perform an action on a bookmark
case "$(printf 'Open\nCopy\nType\nPlay' | 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 -
		;;
	"Play")
		mpv "$link"
		;;
	*)
		exit
		;;
esac