Skip to content

Instantly share code, notes, and snippets.

@hiqua
Created July 8, 2021 16:12
Show Gist options
  • Save hiqua/a40ad6023716f2a8766b48c338f28479 to your computer and use it in GitHub Desktop.
Save hiqua/a40ad6023716f2a8766b48c338f28479 to your computer and use it in GitHub Desktop.
Reconstruct a hledger balance as a file hierarchy where the files' size are proportional to the accounts' balances
#!/bin/bash
set -e
set -u
set -o pipefail
hledger b -S expenses --value=end,"CHF" --infer-value -O csv --flat |\
head -n -1 |\
tail -n +2 |\
sed 's/CHF//' |\
sed 's/:/\//g' |\
xsv select 1,2 |\
xsv fmt -t '\t' |\
while read -r row ; do
# printf "row: %s\n" "$row"
full_path="$(printf "%s" "$row" | cut -f1)"
mkdir -p "$(dirname $full_path)"
amount="$(printf "%s" "$row" | cut -f2 | sed 's/,//g')"
amount="$(echo "$amount * 1000" | bc)"
amount="${amount%%\.00}"
if [ ! -f "$full_path" ]; then
dd if=/dev/zero of="$full_path" bs="$amount" count=1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment