Преглед на файлове

Added the ledger util command

Samuel W. Flint преди 8 години
родител
ревизия
1241660bbb
променени са 1 файла, в които са добавени 58 реда и са изтрити 0 реда
  1. 58 0
      ledger-util

+ 58 - 0
ledger-util

@@ -0,0 +1,58 @@
+#!/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