blob: 57b14c70017346b06cea86c1c30ca153fe198c3d (
plain) (
blame)
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
|
#!/bin/sh
set -eu
file="$HOME/.bookmarks"
touch "$file"
has_notify=$(command -v notify-send >/dev/null 2>&1 && echo 1 || echo 0)
notify() { [ "$has_notify" = 1 ] && notify-send -u "$1" "bookmark" "$2" || true; }
# Primary selection first, fall back to clipboard
bookmark="$(xclip -o -selection primary 2>/dev/null || true)"
[ -z "$bookmark" ] && bookmark="$(xclip -o -selection clipboard 2>/dev/null || true)"
bookmark="$(printf '%s' "$bookmark" | sed 's/[[:space:]]\+$//')"
if [ -z "$bookmark" ]; then
notify critical "Nothing selected or in clipboard"
exit 1
fi
if awk -F'\t' '{print $1}' "$file" | grep -Fxq -- "$bookmark"; then
notify low "Already bookmarked"
exit 0
fi
bookmarkEdit="$(printf '%s' "$bookmark" | dmenu -p "Edit bookmark:")"
out="${bookmarkEdit:-$bookmark}"
comment="$(printf '' | dmenu -p "Add comment (optional):")"
if [ -n "${comment:-}" ]; then
line="$(printf '%s\t# %s' "$out" "$comment")"
else
line="$out"
fi
printf '%s\n' "$line" >> "$file"
notify normal "Saved: $out"
|