aboutsummaryrefslogtreecommitdiff
path: root/citekey-menu
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukasz.kasprzak@pm.me>2026-01-29 01:27:17 +0100
committerLukasz Kasprzak <lukasz.kasprzak@pm.me>2026-01-29 01:27:17 +0100
commit70e6d80c2d367480478eacf46363ee88a0e994ff (patch)
tree3585660271002a776a8756994c92f8e546f98044 /citekey-menu
parent646bb0d8df0e720c966dc2992dcf7fe1154d17cf (diff)
downloadbin-70e6d80c2d367480478eacf46363ee88a0e994ff.tar.gz
bin-70e6d80c2d367480478eacf46363ee88a0e994ff.zip
added lots of new dmenu scripts
Diffstat (limited to 'citekey-menu')
-rwxr-xr-xcitekey-menu28
1 files changed, 28 insertions, 0 deletions
diff --git a/citekey-menu b/citekey-menu
new file mode 100755
index 0000000..3b94bbe
--- /dev/null
+++ b/citekey-menu
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BIB="${BIB:-/home/lukasz/thesis_main/05_thesis/bibliography.bib}"
+DMENU="${DMENU:-dmenu -i -l 20 -p Citekey}"
+CLIP="${CLIP:-xclip -selection clipboard}"
+
+if [[ ! -r "$BIB" ]]; then
+ printf "ERROR: cannot read %s\n" "$BIB" >&2
+ exit 1
+fi
+
+# Build menu lines: "type<TAB>citekey"
+choices="$(
+ rg -n '^\@(\w+)\{([^,]+),' "$BIB" \
+ | sed -E 's/^[0-9]+:\@(\w+)\{([^,]+),/\1\t\2/' \
+ | sort -u
+)"
+
+picked="$(printf "%s\n" "$choices" | eval "$DMENU" || true)"
+[[ -z "$picked" ]] && exit 0
+
+key="$(printf "%s" "$picked" | awk -F'\t' '{print $2}')"
+[[ -z "$key" ]] && exit 0
+
+printf "[@%s]" "$key" | eval "$CLIP"
+printf "Copied: [@%s]\n" "$key" >&2
+