blob: 40f299e70cb1840b6f4c2b3c808c0f307e409b49 (
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
38
39
40
|
#!/bin/sh
set -eu
file="$HOME/.snippets"
mkdir -p "$(dirname "$file")"
touch "$file"
# Choose ONE source:
bookmark="$(xclip -o -selection primary 2>/dev/null || true)" # mouse highlight
# bookmark="$(xclip -o -selection clipboard 2>/dev/null || true)" # Ctrl+C clipboard
# Strip trailing whitespace/newlines (common when copying)
bookmark="$(printf '%s' "$bookmark" | sed 's/[[:space:]]\+$//')"
if [ -z "$bookmark" ]; then
notify-send "No string highlighted!" "Please select/copy a string to bookmark"
exit 1
fi
# Duplicate check: strip tab-separated comments before comparing
if awk -F'\t' '{print $1}' "$file" | grep -Fxq -- "$bookmark"; then
notify-send "Oops" "Already Bookmarked!"
exit 0
fi
# Optionally edit the bookmark text before saving
bookmarkEdit="$(printf '%s' "$bookmark" | dmenu -p "Edit bookmark:")"
out="${bookmarkEdit:-$bookmark}"
# Optionally add a comment (shown in dmenu search, not pasted)
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-send "Bookmark added!" "$out is now saved to the file"
|