12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/bin/zsh -f
- if [[ $# -eq 0 ]] ; then
- echo "ledger-util [ name | list | new name | edit name ]"
- exit
- fi
- function list-utilities () {
- for utility in ~/.ledger/utilities/*.sh ;
- do
- echo " - $(basename -- ${utility} .sh)"
- done
- }
- function new-utility () {
- name=$1
- shift
- cat <<EOF >~/.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
- 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
|