ledger-util 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/zsh -f
  2. if [[ $# -eq 0 ]] ; then
  3. echo "ledger-util [ name | list | new name | edit name ]"
  4. exit
  5. fi
  6. function list-utilities () {
  7. for utility in ~/.ledger/utilities/*.sh ;
  8. do
  9. echo " - $(basename -- ${utility} .sh)"
  10. done
  11. }
  12. function new-utility () {
  13. name=$1
  14. shift
  15. cat <<EOF >~/.ledger/utilities/${name}.sh
  16. #!/bin/sh
  17. # Ledger Utility ${name}
  18. EOF
  19. edit-utility ${name}
  20. }
  21. function edit-utility () {
  22. name=$1
  23. shift
  24. emacsclient --alternate-editor="" -n ~/.ledger/utilities/${name}.sh
  25. }
  26. function run-utility () {
  27. name=$1
  28. shift
  29. if [[ -e ~/.ledger/utilities/${name}.sh ]] ; then
  30. ~/.ledger/utilities/${name}.sh $*
  31. else
  32. echo Utility ${name} not defined.
  33. fi
  34. }
  35. name=$1
  36. shift
  37. case ${name} in
  38. list)
  39. list-utilities
  40. ;;
  41. new)
  42. new-utility $*
  43. ;;
  44. edit)
  45. edit-utility $*
  46. ;;
  47. *)
  48. run-utility $name $*
  49. esac