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