aboutsummaryrefslogtreecommitdiff
path: root/citekey-menu
diff options
context:
space:
mode:
Diffstat (limited to 'citekey-menu')
-rwxr-xr-xcitekey-menu19
1 files changed, 14 insertions, 5 deletions
diff --git a/citekey-menu b/citekey-menu
index 3b94bbe..d8db51e 100755
--- a/citekey-menu
+++ b/citekey-menu
@@ -1,8 +1,9 @@
#!/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}"
+BIB="${BIB:-/home/lukasz/git/thesis_main/05_thesis/bibliography.bib}"
+DMENU_KEY="${DMENU_KEY:-dmenu -i -l 20 -p Citekey}"
+DMENU_LOC="${DMENU_LOC:-dmenu -i -p 'Locator (optional)'}"
CLIP="${CLIP:-xclip -selection clipboard}"
if [[ ! -r "$BIB" ]]; then
@@ -17,12 +18,20 @@ choices="$(
| sort -u
)"
-picked="$(printf "%s\n" "$choices" | eval "$DMENU" || true)"
+picked="$(printf "%s\n" "$choices" | eval "$DMENU_KEY" || 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
+# Optional locator, e.g. 84 / 11-13 / xxi
+locator="$(printf '\n' | eval "$DMENU_LOC" || true)"
+if [[ -n "${locator// }" ]]; then
+ citation="[@$key, $locator]"
+else
+ citation="[@$key]"
+fi
+
+printf "%s" "$citation" | eval "$CLIP"
+printf "Copied: %s\n" "$citation" >&2