|
@@ -1,12 +1,12 @@
|
|
|
#!/bin/zsh -f
|
|
|
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
|
- echo "ledgerutil [ name | list | new name | edit name ]"
|
|
|
+ echo "ledgerutil [ name | list | new name [ perl | shell | python ] | edit name ]"
|
|
|
exit
|
|
|
fi
|
|
|
|
|
|
function list-utilities () {
|
|
|
- for utility in ~/.ledger/utilities/*.(sh|pl) ;
|
|
|
+ for utility in ~/.ledger/utilities/*.(sh|pl|py) ;
|
|
|
do
|
|
|
case $utility in
|
|
|
*.sh)
|
|
@@ -14,6 +14,9 @@ function list-utilities () {
|
|
|
;;
|
|
|
*.pl)
|
|
|
echo " - $(basename -- ${utility} .pl)"
|
|
|
+ ;;
|
|
|
+ *.py)
|
|
|
+ echo " - $(basename -- ${utility} .py)"
|
|
|
esac
|
|
|
done
|
|
|
}
|
|
@@ -21,19 +24,50 @@ function list-utilities () {
|
|
|
function new-utility () {
|
|
|
name=$1
|
|
|
shift
|
|
|
- cat <<EOF >~/.ledger/utilities/${name}.sh
|
|
|
+ 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 () {
|
|
|
name=$1
|
|
|
shift
|
|
|
- emacsclient --alternate-editor="" -n ~/.ledger/utilities/${name}.sh
|
|
|
+ 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 () {
|
|
@@ -42,12 +76,12 @@ function run-utility () {
|
|
|
|
|
|
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
|
|
|
- if [[ -e ~/.ledger/utilities/${name}.pl ]] ; then
|
|
|
- ~/.ledger/utilities/${name}.pl $*
|
|
|
- else
|
|
|
- echo Utility ${name} not defined.
|
|
|
- fi
|
|
|
+ echo Utility ${name} not defined.
|
|
|
fi
|
|
|
}
|
|
|
|