#!/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. 
bkmk="$(xclip -o -selection primary)"
alias bmnotify-send="notify-send -i $HOME/.local/share/img/bm-icon.png"
if isflag '-a' "$@" ; then 
	bkmk="$(dmenu -p "Enter bookmark: " < /dev/null)"
fi
[ -z "$bkmk" ] && bmnotify-send "Did not bookmark." "Nothing selected to bookmark!" && exit
comment="$(dmenu -p "Add comment ($bkmk): " < /dev/null)"
[ -z "$comment" ] && exit
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/bookmark"
else
	file="$ORGD_KT_PATH/bookmark"
fi
stripped="$(strip-comments "$file")"
if echo "$stripped" | grep -q "^$bkmk[/ \t]*$"; then 
	bmnotify-send "No!" "$bkmk already bookmarked!"
else
	echo "$bkmk # $comment" >> "$file"
	bmnotify-send "Bookmark Added!" "$bkmk added and tagged as $comment."
fi