summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/README5
-rwxr-xr-xscripts/bal27
-rwxr-xr-xscripts/entry16
-rwxr-xr-xscripts/getquote16
-rwxr-xr-xscripts/mean27
-rwxr-xr-xscripts/profit2
-rwxr-xr-xscripts/reg14
-rwxr-xr-xscripts/report17
-rwxr-xr-xscripts/spending8
-rwxr-xr-xscripts/worth2
10 files changed, 134 insertions, 0 deletions
diff --git a/scripts/README b/scripts/README
new file mode 100644
index 00000000..7221f95f
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,5 @@
+This scripts are provided just in the way of giving ideas. They
+probably all need to be modified to suit your particular environment.
+Beware!
+
+John
diff --git a/scripts/bal b/scripts/bal
new file mode 100755
index 00000000..7fdf54ca
--- /dev/null
+++ b/scripts/bal
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+switch=""
+current="-c"
+limit="-l \$50"
+negonly="-N ^Liabilities"
+
+if [ "$1" = "-C" -o "$1" = "-U" -o "$1" = "-P" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" ]; then
+ current="$1 $2"
+ shift 2
+fi
+
+accts="$@"
+if [ -z "$accts" ]; then
+ accts="-Equity -Income -Expenses"
+ if [ ! "$switch" = "-P" ]; then
+ accts="$accts -Savings -Retirement"
+ fi
+else
+ limit=""
+ negonly=""
+fi
+
+ledger $current $limit $negonly -s $switch balance $accts
diff --git a/scripts/entry b/scripts/entry
new file mode 100755
index 00000000..28daf8c8
--- /dev/null
+++ b/scripts/entry
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ -z "$LEDGER" -o ! -r $LEDGER ]; then
+ echo Please set your LEDGER environment variable.
+fi
+
+line=`wc -l $LEDGER | awk '{print $1}'`
+
+if ledger entry "$@" > /tmp/entry; then
+ cat /tmp/entry >> $LEDGER
+else
+ echo "$@" >> $LEDGER
+fi
+rm /tmp/entry
+
+vi +$line $LEDGER
diff --git a/scripts/getquote b/scripts/getquote
new file mode 100755
index 00000000..cf8c8abd
--- /dev/null
+++ b/scripts/getquote
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+exit 0 if $ARGV[0] eq "\$";
+
+use Finance::Quote;
+
+$q = Finance::Quote->new;
+
+$q->timeout(60);
+$q->require_labels(qw/price/);
+
+%quotes = $q->fetch("nasdaq", $ARGV[0]);
+
+if ($quotes{$ARGV[0], "price"}) {
+ print "\$", $quotes{$ARGV[0], "price"}, "\n";
+}
diff --git a/scripts/mean b/scripts/mean
new file mode 100755
index 00000000..3c6f779a
--- /dev/null
+++ b/scripts/mean
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+$last = $ARGV[-1];
+splice(@ARGV, -1);
+
+open(PIPE, "ledger -MG @ARGV register $last |") || die;
+@values = ();
+while (<PIPE>) {
+ ($date, $value) = split;
+ push @values, $value;
+}
+close(PIPE);
+
+@values = sort @values;
+splice(@values, 0, 1);
+splice(@values, -1);
+
+$value = 0.0;
+for $item (@values) {
+ $value += $item;
+}
+
+if (@values) {
+ printf("%.2f\n", $value / @values);
+} else {
+ die "There are no values to average!\n";
+}
diff --git a/scripts/profit b/scripts/profit
new file mode 100755
index 00000000..26f112d1
--- /dev/null
+++ b/scripts/profit
@@ -0,0 +1,2 @@
+#!/bin/sh
+ledger "$@" balance ^Income$ ^Expenses$
diff --git a/scripts/reg b/scripts/reg
new file mode 100755
index 00000000..75ac364e
--- /dev/null
+++ b/scripts/reg
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+switch="-U"
+current="-c"
+
+if [ "$1" = "-C" -o "$1" = "-U" -o "$1" = "-P" -o "$1" = "-M" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" ]; then
+ current="$1 $2"
+ shift 2
+fi
+
+ledger $current -s $switch register "$@"
diff --git a/scripts/report b/scripts/report
new file mode 100755
index 00000000..aa42982e
--- /dev/null
+++ b/scripts/report
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+dir=$HOME/doc/finance
+
+cd /tmp
+
+ledger -M -G register "$@" > $1
+
+gnuplot <<EOF
+set terminal png
+set output "report.png"
+set xdata time
+set timefmt "%Y/%m/%d"
+plot "$1" using 1:2 with linespoints
+EOF
+
+open report.png
diff --git a/scripts/spending b/scripts/spending
new file mode 100755
index 00000000..895c4170
--- /dev/null
+++ b/scripts/spending
@@ -0,0 +1,8 @@
+#!/bin/sh
+ledger "$@" balance \
+ Expenses:Food \
+ Expenses:Movies \
+ Expenses:Auto:Gas \
+ Expenses:Tips \
+ Expenses:Health \
+ Expenses:Supplies
diff --git a/scripts/worth b/scripts/worth
new file mode 100755
index 00000000..58b20440
--- /dev/null
+++ b/scripts/worth
@@ -0,0 +1,2 @@
+#!/bin/sh
+ledger "$@" balance ^Assets$ ^Liabilities$