about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-03-20T15·11+0000
committerWilliam Carroll <wpcarro@gmail.com>2019-03-20T15·11+0000
commitef2b9342682dd693b203c293520a849c8f3b40c1 (patch)
tree370b264a3b9628a0b405412d696238cf0a41697c
parent74a1595bc929af38528599fedb6dee6d60266bd0 (diff)
Support retrieving Monzo balance
This is intended to be an i3 status bar integration eventually. As long as the
monzo_creds file stays encrypted and out of a public GH repository, this should
be fairly secure.
-rw-r--r--configs/shared/zsh/functions.zsh20
1 files changed, 20 insertions, 0 deletions
diff --git a/configs/shared/zsh/functions.zsh b/configs/shared/zsh/functions.zsh
index 60e512e8fb79..ae259853978b 100644
--- a/configs/shared/zsh/functions.zsh
+++ b/configs/shared/zsh/functions.zsh
@@ -172,6 +172,26 @@ kush() {
 }
 
 # Misc
+monzo_balance() {
+  # Return the balance of my Monzo bank account. Intended to be used in my i3
+  # status bar.
+  # Usage: monzo_balance
+  # Depends:
+  #   - ~/Dropbox/monzo_creds.json.gpg (encrypted asymmetrically for yourself)
+  #   - httpie
+  #   - jq
+  #   - gpg
+  local creds=$(gpg --decrypt ~/Dropbox/monzo_creds.json.gpg 2>/dev/null)
+  local access_token=$(echo $creds | jq --raw-output .access_token)
+  local account_id=$(echo $creds | jq --raw-output .account_id)
+  local balance=$(http --body https://api.monzo.com/balance \
+                       "Authorization: Bearer ${access_token}" \
+                       "account_id==${account_id}" | \
+                    jq .balance)
+
+  echo "£$balance"
+}
+
 tldr_docs() {
   # Helper function for submitting a new page to `tldr`.
   # Usage: tldr_docs <cmd-name>