blob: b7dcf78c9c1f0c9fcd5d09be0d957bce4dbffa9f (
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
69
70
71
72
73
74
|
#!/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")
[ -z "$link" ] && exit 1
# 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
|