bash scripts I use on the iphone

52 views
Skip to first unread message

sims

unread,
Jun 24, 2009, 10:24:17 AM6/24/09
to Ledger
Here are a couple of simple bash scripts I wrote for my iphone to
automate ledger creation. Of course you'll need a jail broken iphone
and the terminal. I call one o.sh and the other i.sh. Then I use the
menu to type ./o.sh for me and I just have to enter a few keystrokes
and press return. Please customize to suit. I hope someone finds this
useful. Please let me know any suggestions or improvements.

#!/bin/sh
# script to
# accept input:
# * amount
# * account
# * note
# output:
# * ledger format text
# automatically includes date and source account (wallet)
#

fname='wallet.ledger'
if [ ! -z "$2" ]; then

account='expenses:simon:'$2
if [ $2 = 'f' ]; then
account='expenses:simon:food'
fi
if [ $2 = 'o' ]; then
account='expenses:simon:transportation:oil'
fi
if [ $2 = 'p' ]; then
account='expenses:simon:transportation::parking'
fi
if [ $2 = 't' ]; then
account='expenses:simon:telecom'
fi
if [ $2 = 'd' ]; then
account='expenses:simon:drinks'
fi
if [ $2 = 'g' ]; then
account='expenses:simon:gift'
fi

echo `date +%Y/%m/%d` ' ' $3 >> $fname
echo ' ' $account ' ' $1 >> $fname
echo ' assets:cash:wallet' >> $fname
echo >> $fname

else
echo "usage: $0 amount account note"
fi


#!/bin/sh
# script to
# accept input:
# * amount
# * account
# * subaccount
# * note
# output:
# * ledger format text
# automatically includes date and destination account (wallet)
#

fname='wallet.ledger'
account='income:'$2':'$3

if [ ! -z $3 ]; then

if [ $2 = 'b' ]; then
account='assets:bank:'$3
fi
if [ $2 = 'a' ]; then
account='assets:accounts receivable:'$3
fi
if [ $2 = 'p' ]; then
account='assets:payback:'$3
fi
if [ $2 = 'c' ]; then
account='income:other:cash:'$3
fi

echo `date +%Y/%m/%d` ' ' $4 >> $fname
echo ' assets:cash:wallet ' $1 >> $fname
echo ' ' $account >> $fname
echo >> $fname

else
echo "usage: $0 amount account subaccount note"
fi

Damian Gerow

unread,
Jun 24, 2009, 10:58:46 AM6/24/09
to ledge...@googlegroups.com
These are fantastic! A nice way to port ledger around in your pocket,
without needing to write up a full UI.

I've taken the liberty of re-writing them to use 'case' instead of a
sequence of if statements:

-----


#!/bin/sh
# script to
# accept input:
# * amount
# * account
# * note
# output:
# * ledger format text
# automatically includes date and source account (wallet)
#

fname='wallet.ledger'
if [ -z "$2" ]; then
echo "usage: $0 amount account [note]"
exit 255
fi

case "$2" in
"d")
account='expenses:simon:drinks'
;;
"g")
account='expenses:simon:gift'
;;
"f")
account="expenses:simon:food"
;;
"o")


account='expenses:simon:transportation:oil'

;;
"p")


account='expenses:simon:transportation::parking'

;;
"t")
account='expenses:simon:telecom'
;;
esac

echo `date +%Y/%m/%d` ' ' $3 >> $fname
echo ' ' $account ' ' $1 >> $fname
echo ' assets:cash:wallet' >> $fname
echo >> $fname

fi
----

P.S. +1 for using cash everywhere.

sims

unread,
Jun 24, 2009, 9:43:38 PM6/24/09
to Ledger
Thanks! Yeah, I've never liked cards. Cash man! Show me the money!

Nice rewrite. case. I forgot about that one. One difference that I
should point out is that: if none of the second arguments match, there
will be a default:
account='expenses:simon:'$2
account='income:'$2':'$3

I guess just put that before the case. Basically if I don't input one
of those single letters it will use directly what was input on the
command line as an (sub)account name. Makes sense?

It would be cool to have something like kommander for the iphone.
Apple... arg... The only reason I have an iphone is because they are
free here in Japan... I would not mind compiling ledger for the iphone
though. Seems like I need Boost, GMP, and MPFR. Hmmm... I don't know
if those are ported to the iphone.

I've finished my invoice script and am working on a receipt script.
I'll post those soon.

Cheers!

Damian Gerow

unread,
Jun 24, 2009, 10:26:56 PM6/24/09
to ledge...@googlegroups.com
sims wrote:
: Nice rewrite. case. I forgot about that one. One difference that I

: should point out is that: if none of the second arguments match, there
: will be a default:
: account='expenses:simon:'$2
: account='income:'$2':'$3

Before the esac, put in:

*) account="expenses:simon:misc"
;;

(Or something like that...)

Reply all
Reply to author
Forward
0 new messages