aboutsummaryrefslogtreecommitdiff
path: root/hledger-category-select
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-05-10 22:57:02 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-05-10 22:57:02 +0200
commit3cd9138c9d8fb9be248c75330cca9da47f4d2e8a (patch)
treeb3b677a9c1a474589f45d20953028a987fa73b80 /hledger-category-select
parent83f7fe4b8402bab171d110703a1b1115efbc9b28 (diff)
downloadbin-3cd9138c9d8fb9be248c75330cca9da47f4d2e8a.tar.gz
bin-3cd9138c9d8fb9be248c75330cca9da47f4d2e8a.zip
added a whole bunch of scripts
Diffstat (limited to 'hledger-category-select')
-rwxr-xr-xhledger-category-select35
1 files changed, 35 insertions, 0 deletions
diff --git a/hledger-category-select b/hledger-category-select
new file mode 100755
index 0000000..7b34ff4
--- /dev/null
+++ b/hledger-category-select
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+FILE="${FILE:-$HOME/docs/priv/finance/hledger_main/accounts.journal}"
+DMENU="${DMENU:-dmenu -i -l 20 -p 'Account:'}"
+CLIP="${CLIP:-xclip -selection clipboard}"
+
+if [[ ! -r "$FILE" ]]; then
+ printf 'ERROR: cannot read %s\n' "$FILE" >&2
+ exit 1
+fi
+
+# Extract account names:
+# - only lines starting with: account ...
+# - strip the leading "account " part
+# - sort uniquely
+choices="$(
+ awk '
+ /^[[:space:]]*account[[:space:]]+/ {
+ sub(/^[[:space:]]*account[[:space:]]+/, "", $0)
+ print
+ }
+ ' "$FILE" | sort -u
+)"
+
+[[ -z "$choices" ]] && {
+ printf 'ERROR: no account entries found in %s\n' "$FILE" >&2
+ exit 1
+}
+
+picked="$(printf '%s\n' "$choices" | eval "$DMENU" || true)"
+[[ -z "$picked" ]] && exit 0
+
+printf '%s' "$picked" | eval "$CLIP"
+printf 'Copied: %s\n' "$picked" >&2