summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ledger.vim46
-rw-r--r--contrib/scripts/README4
-rwxr-xr-xcontrib/scripts/bal21
-rwxr-xr-xcontrib/scripts/bal-huquq21
-rwxr-xr-xcontrib/scripts/entry16
-rwxr-xr-xcontrib/scripts/getquote16
-rwxr-xr-xcontrib/scripts/ledger-du49
-rwxr-xr-xcontrib/scripts/report21
-rwxr-xr-xcontrib/scripts/tc7
-rwxr-xr-xcontrib/scripts/ti5
-rwxr-xr-xcontrib/scripts/to3
-rwxr-xr-xcontrib/scripts/trend30
12 files changed, 239 insertions, 0 deletions
diff --git a/contrib/ledger.vim b/contrib/ledger.vim
new file mode 100644
index 00000000..df63feb8
--- /dev/null
+++ b/contrib/ledger.vim
@@ -0,0 +1,46 @@
+" Vim syntax file
+" filetype: ledger
+" Version: 0.0.2
+" by Wolfgang Oertl; Use according to the terms of the GPL>=2.
+" Revision history
+" 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
+
+if version < 600
+ syntax clear
+elseif exists("b:current_sytax")
+ finish
+endif
+
+" for debugging
+syntax clear
+
+" region: a normal transaction
+syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend transparent contains=transDate
+syn match transDate /^\d\S\+/ contained
+syn match Comment /^;.*$/
+" highlight default link transNorm Question
+highlight default link Comment SpecialKey
+highlight default link transDate Question
+
+" folding: how to represent a transaction in one line.
+function! MyFoldText()
+ let line = strpart(getline(v:foldstart), 0, 65)
+ " get the amount at the end of the second line
+ let line2 = getline(v:foldstart+1)
+ let pos = match(line2, "[0-9.]*$")
+ let line2 = strpart(line2, pos)
+ let pad_len = 80 - strlen(line) - strlen(line2)
+ if (pad_len < 0) then
+ pad_len = 0
+ endif
+ let pad = strpart(" ", 0, pad_len)
+ return line . pad . line2
+endfunction
+set foldtext=MyFoldText()
+set foldmethod=syntax
+
+" syncinc is easy: search for the first transaction.
+syn sync clear
+syn sync match ledgerSync grouphere transNorm "^\d"
+
+let b:current_syntax = "ledger"
diff --git a/contrib/scripts/README b/contrib/scripts/README
new file mode 100644
index 00000000..6108afbf
--- /dev/null
+++ b/contrib/scripts/README
@@ -0,0 +1,4 @@
+This scripts are provided just to give some ideas. They probably need
+to be modified to better suit your environment. Beware!
+
+John
diff --git a/contrib/scripts/bal b/contrib/scripts/bal
new file mode 100755
index 00000000..423e3e41
--- /dev/null
+++ b/contrib/scripts/bal
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+switch="-c"
+limit="-t (/Liabilities/?a<0:Ua>100)&a"
+
+if [ "$1" = "-C" -o "$1" = "-U" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" -o "$1" = "-p" ]; then
+ switch="$1 $2"
+ shift 2
+fi
+
+accts="$@"
+if [ -z "$accts" ]; then
+ accts="-Equity -Income -Expenses"
+else
+ limit=""
+fi
+
+ledger -VQ $switch $limit -s -S "-UT" balance $accts
diff --git a/contrib/scripts/bal-huquq b/contrib/scripts/bal-huquq
new file mode 100755
index 00000000..fad2854a
--- /dev/null
+++ b/contrib/scripts/bal-huquq
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+switch="-c"
+limit="-t (/Liabilities/?(/Huquq/?a/P{2.22AU}<={-1.0}:a<0):Ua>100)&a"
+
+if [ "$1" = "-C" -o "$1" = "-U" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" -o "$1" = "-p" ]; then
+ switch="$1 $2"
+ shift 2
+fi
+
+accts="$@"
+if [ -z "$accts" ]; then
+ accts="-Equity -Income -Expenses"
+else
+ limit=""
+fi
+
+ledger -VQ $switch $limit -s -S "-UT" balance $accts
diff --git a/contrib/scripts/entry b/contrib/scripts/entry
new file mode 100755
index 00000000..cc030d8e
--- /dev/null
+++ b/contrib/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/contrib/scripts/getquote b/contrib/scripts/getquote
new file mode 100755
index 00000000..bed561d6
--- /dev/null
+++ b/contrib/scripts/getquote
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+$timeout = 60;
+
+use Finance::Quote;
+
+$q = Finance::Quote->new;
+$q->timeout($timeout);
+$q->require_labels(qw/price/);
+
+%quotes = $q->fetch("nasdaq", $ARGV[0]);
+if ($quotes{$ARGV[0], "price"}) {
+ print "\$", $quotes{$ARGV[0], "price"}, "\n";
+} else {
+ exit 1;
+}
diff --git a/contrib/scripts/ledger-du b/contrib/scripts/ledger-du
new file mode 100755
index 00000000..f5d7dd7d
--- /dev/null
+++ b/contrib/scripts/ledger-du
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import string
+import sys
+import os
+import time
+
+from stat import *
+from os.path import *
+
+def report_file(path):
+ dir_elems = string.split(dirname(path), os.sep)
+ if dir_elems[0] == "." or dir_elems[0] == "":
+ dir_elems = dir_elems[1 :]
+ account = string.join(dir_elems, ":")
+
+ info = os.stat(path)
+ print time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])),
+
+ print basename(path)
+ print " ", account, " ", info[ST_SIZE], "b"
+ print " Equity:Files"
+ print
+
+def find_files(path):
+ entries = os.listdir(path)
+ for entry in entries:
+ entry = join(path, entry)
+ if not islink(entry):
+ if isdir(entry) and entry != "/proc":
+ find_files(entry)
+ else:
+ report_file(entry)
+
+args = sys.argv[1:]
+if len(args):
+ paths = args
+else:
+ paths = ["."]
+
+print """
+C 1.00 Kb = 1024 b
+C 1.00 Mb = 1024 Kb
+C 1.00 Gb = 1024 Mb
+C 1.00 Tb = 1024 Gb
+"""
+
+for path in paths:
+ find_files(path)
diff --git a/contrib/scripts/report b/contrib/scripts/report
new file mode 100755
index 00000000..24418cdc
--- /dev/null
+++ b/contrib/scripts/report
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# This script facilities plotting of a ledger register report. If you
+# use OS/X, and have AquaTerm installed, you will probably want to set
+# LEDGER_TERM to "aqua".
+#
+# Examples of use:
+#
+# report -j -M reg food # plot monthly food costs
+# report -J reg checking # plot checking account balance
+
+if [ -z "$LEDGER_TERM" ]; then
+ LEDGER_TERM="x11 persist"
+fi
+
+(cat <<EOF; ledger "$@") | gnuplot
+ set terminal $LEDGER_TERM
+ set xdata time
+ set timefmt "%Y/%m/%d"
+ plot "-" using 1:2 with lines
+EOF
diff --git a/contrib/scripts/tc b/contrib/scripts/tc
new file mode 100755
index 00000000..c24be99a
--- /dev/null
+++ b/contrib/scripts/tc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+timeclock out
+
+proj="$1"
+shift
+timeclock in "$proj" "$@"
diff --git a/contrib/scripts/ti b/contrib/scripts/ti
new file mode 100755
index 00000000..a7214e65
--- /dev/null
+++ b/contrib/scripts/ti
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+proj="$1"
+shift
+timeclock in "$proj" "$@"
diff --git a/contrib/scripts/to b/contrib/scripts/to
new file mode 100755
index 00000000..3198db3c
--- /dev/null
+++ b/contrib/scripts/to
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+timeclock out "$@"
diff --git a/contrib/scripts/trend b/contrib/scripts/trend
new file mode 100755
index 00000000..3c189c0b
--- /dev/null
+++ b/contrib/scripts/trend
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# This script requires Python support.
+#
+# To use, just run "trend" with the accounts to compute the trend for:
+#
+# trend dining
+#
+# The trend values are not terribly meaningful, but this gives an
+# example of how Python can be used to create more complex reports.
+
+ledger --import-stdin -T "@rdev()" reg "$@" <<EOF
+import ledger
+
+mean = ledger.parse_value_expr ("AT")
+last_mean = None
+last_dev = None
+
+def rdev (details):
+ global last_mean, last_dev
+ mval = mean.compute (details)
+ if last_mean is None:
+ dev = ledger.Value ()
+ else:
+ dev = mval - last_mean
+ dev = (last_dev + dev) / 2
+ last_mean = mval
+ last_dev = dev
+ return dev
+EOF