From 3cd9138c9d8fb9be248c75330cca9da47f4d2e8a Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Sun, 10 May 2026 22:57:02 +0200 Subject: added a whole bunch of scripts --- hledger-category-select | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 hledger-category-select (limited to 'hledger-category-select') 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 -- cgit v1.3