#!/bin/zsh -f if [[ $# -eq 0 ]] ; then echo "ledgerutil [ name | list | new name | edit name ]" exit fi function list-utilities () { for utility in ~/.ledger/utilities/*.(sh|pl) ; do case $utility in *.sh) echo " - $(basename -- ${utility} .sh)" ;; *.pl) echo " - $(basename -- ${utility} .pl)" esac done } function new-utility () { name=$1 shift cat <~/.ledger/utilities/${name}.sh #!/bin/sh # Ledger Utility ${name} EOF edit-utility ${name} } function edit-utility () { name=$1 shift emacsclient --alternate-editor="" -n ~/.ledger/utilities/${name}.sh } function run-utility () { name=$1 shift if [[ -e ~/.ledger/utilities/${name}.sh ]] ; then ~/.ledger/utilities/${name}.sh $* else if [[ -e ~/.ledger/utilities/${name}.pl ]] ; then ~/.ledger/utilities/${name}.pl $* else echo Utility ${name} not defined. fi fi } name=$1 shift case ${name} in list) list-utilities ;; new) new-utility $* ;; edit) edit-utility $* ;; *) run-utility $name $* esac