aboutsummaryrefslogtreecommitdiff
path: root/scripts/buku-archive.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/buku-archive.sh')
-rwxr-xr-xscripts/buku-archive.sh26
1 files changed, 21 insertions, 5 deletions
diff --git a/scripts/buku-archive.sh b/scripts/buku-archive.sh
index 5af56a0..6ce1e80 100755
--- a/scripts/buku-archive.sh
+++ b/scripts/buku-archive.sh
@@ -1,12 +1,28 @@
#!/usr/bin/env bash
-set -x
-SEL="$(xsel)"
-BOOKMARK_ID="$(buku "$SEL" -f 1 --tacit | tail -n +2 | awk '{print $1}')"
-# tail to trim unwanted "waiting for input" output from buku https://github.com/jarun/Buku/blob/d60d56bc9f7f5e1410e99dc8bb4e35abf5068a14/buku#L4619
+SEL="$(xclip -o | tr -d '\n')"
+if [[ -z "${SEL// }" ]]; then
+ echo "Empty selection."
+ exit 1
+fi
+BOOKMARK_ID=
+IFS="
+"
+BOOKMARKS="$(buku "$SEL" -f 1 --tacit)"
+
+for bookmark in $BOOKMARKS; do
+ echo "$bookmark"
+ ID="$(echo "$bookmark" | cut -d$'\t' -f 1)"
+ URL="$(echo "$bookmark" | cut -d$'\t' -f 2)"
+ if [[ "$URL" = "$SEL" ]]; then
+ BOOKMARK_ID="$ID"
+ break
+ fi
+done
+
if [[ ! -z "$BOOKMARK_ID" ]]; then
- echo "Archiving $BOOKMARK_ID."
+ echo "Archiving $BOOKMARK_ID (URL: $SEL)."
buku -u "$BOOKMARK_ID" --tag - ril
buku -u "$BOOKMARK_ID" --tag + simple-archive
else