-
Notifications
You must be signed in to change notification settings - Fork 0
/
d-bookmark
executable file
·53 lines (37 loc) · 1.6 KB
/
d-bookmark
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
#!/usr/bin/env bash
source d-var.conf
bookmark="${1:-$(printf "%s\n%s" "$(wl-paste -p)" "$(wl-paste)" | $D_MENU -i -p ' ')}"
#file="$HOME/.local/share/dict/bookmarks"
file="$HOME/d-sync/notes/bookmarks.org"
# Just a variable to show as prompt while adding name (confirmation)
site="$(echo "${bookmark}" | sed 's/ //g')"
if [[ -z "$site" ]]; then
exit 0
elif grep -qF "$site" "$file"; then
notify-send "Oops.. $site" "Already in bookmark!"
exit 0
fi
# Eg names so you can quickly name
# notify-send
examples=("reddit" "twitter" "git-linux" "git-emacs" "git-droid" "TODO")
title="$(printf '%s\n' "${examples[@]}" | $W_MENU -l 2 -p "${site} => Title" | sed 's/ /-/g')"
# Add your org mode file path here (headings are in level 2 in my file)
getheadings="$(rg "^\*\* " "${file}" | sed '/** gnus/q' | awk '{print $2 }')"
# ^ prints heading upto "** elfeed"
# i have added rest as rss feeds so
tags="$(rg -o "__([[:alnum:][:nonascii:]_-]*)" "$file" | uniq | sed 's/__//g' | $D_MENU -p "${title} => " | sed 's/ /_/g')"
# Prints out the heading text, so `sed` can append it to that heading level
[[ -n "${title}" ]] && section="$(printf "%s" "$getheadings" | $D_MENU -p ' Heading'| sed 's/ //g')"
mark-print ()
{
# Sed appends the link in a clean way
sed -i "/$section$/a + [[$site][${title}__${tags}]]" "$file" &&
notify-send "Bookmark added!" " $site is now saved under ==> $section"
}
if grep -qF "$site" "$file"; then
notify-send "Oops.. $site" "Already in bookmark!"
elif [[ -n "${section}" ]]; then
mark-print
else
notify-send "Give a title & section to add mark"
fi