summaryrefslogtreecommitdiffstats
path: root/contrib/viewxml.sh
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
commitdadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch)
tree99e72842fe687baea16376a147619b6048d7e441 /contrib/viewxml.sh
downloadkmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.tar.gz
kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.zip
Added kmymoney
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'contrib/viewxml.sh')
-rwxr-xr-xcontrib/viewxml.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/contrib/viewxml.sh b/contrib/viewxml.sh
new file mode 100755
index 0000000..cd1ef17
--- /dev/null
+++ b/contrib/viewxml.sh
@@ -0,0 +1,45 @@
+# A bash script to view a temporary copy of a KMyMoney XML file in your favourite editor
+# (works with some gnucash files too!)
+
+# Usage:- viewxml [filename]
+
+# Save this script somewhere in your path and remember to apply execute permissions (chmod a+x viewxml)
+# Set the following variables as required
+TMPDIR=/tmp # a temporary directory for storing the file copy
+EDITOR=kate # your editor of choice
+WIPE='rm -f' # command to get rid of the temporary file copy (could be replaced with a shredder or something)
+#
+
+declare -i TYPE
+
+if [ -z $1 ]; then
+ FILE=`kdialog --getopenfilename . '*.*'`;
+else
+ FILE=$1;
+fi
+
+TYPE=0 # default type, gzipped file
+read -n 14 <$FILE HEAD
+if [ "$HEAD" = "-----BEGIN PGP" ]; then
+ TYPE=1; # encrypted file
+elif [ "$HEAD" = "<?xml version=" ]; then
+ TYPE=2;
+fi
+
+BASENAME=`basename $FILE`
+
+case $TYPE in
+ 0) echo $BASENAME is gzipped
+ cp $FILE $TMPDIR/$BASENAME.gz
+ gunzip $TMPDIR/$BASENAME.gz;;
+ 1) echo $BASENAME is encrypted
+ gpg -d $FILE >$TMPDIR/$BASENAME;;
+ 2) echo $BASENAME is plaintext
+ cp $FILE $TMPDIR/$BASENAME;;
+esac
+
+$EDITOR $TMPDIR/$BASENAME
+
+$WIPE $TMPDIR/$BASENAME
+
+