ledger-util 1.1 KB

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