summaryrefslogtreecommitdiff
path: root/sys/add-coast
diff options
context:
space:
mode:
authorGeorge Abbott <george@gabbott.dev>2023-10-31 17:54:07 +0000
committerGeorge Abbott <george@gabbott.dev>2023-10-31 17:54:07 +0000
commit4d0bd914e7c1ee65f4036e60149a7b891906a5d3 (patch)
treec2a6751823e064e003cd4f6166df07bfc106d7eb /sys/add-coast
Commit all to date.
Diffstat (limited to 'sys/add-coast')
-rwxr-xr-xsys/add-coast40
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/add-coast b/sys/add-coast
new file mode 100755
index 0000000..ebd1df9
--- /dev/null
+++ b/sys/add-coast
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Adds a bookmark.
+# Either grabs xclip, or requests input of the string to bookmark.
+# If passed --ask (-a), then ignore the clipboard and prompt the user what to
+# bookmark.
+
+coast="$(xclip -o -selection primary)"
+alias bmnotify-send="notify-send -i $HOME/.local/share/img/bm-icon.png"
+commonargs="-i $HOME/.local/share/img/bm-icon.png"
+
+if isflag '-a' "$@" ; then
+ coast="$(dmenu -p "Enter coast entry: " < /dev/null)"
+fi
+
+# Exit if entry is not present.
+[ -z "$coast" ] && bmnotify-send "Did not add coast." "Nothing selected to add!" && exit
+
+# Request comment.
+comment="$(dmenu -p "Add comment ($coast): " < /dev/null)"
+
+# Exit if the comment is blank.
+[ -z "$comment" ] && exit
+
+# Find the file which holds coast entries, and process it.
+if [ "$ORGD_KT_PATH" = "" ]; then
+ notify-send "ORGD_KT_PATH empty." "Using $HOME/docs/wr/orgd/kt as fallback."
+ file="$HOME/docs/wr/orgd/kt/coast"
+else
+ file="$ORGD_KT_PATH/coast"
+fi
+stripped="$(strip-comments "$file")"
+
+# Add the entry, unless its already added.
+if echo "$stripped" | grep -q "^$coast[/ \t]*$"; then
+ bmnotify-send "No!" "<i>$coast</i> already added!"
+else
+ echo "$coast # $comment" >> "$file"
+ bmnotify-send "Entry Added!" "<i>$coast</i> added and tagged as <i>$comment</i>." $commonargs
+fi
+