From a523bf95d34bb5f7c610b2c8fd1a5573a42cd978 Mon Sep 17 00:00:00 2001
From: silenc3r <dawid.zych@yandex.com>
Date: Mon, 21 Aug 2017 13:52:26 +0100
Subject: [PATCH] Create datafile parent directory if needed

---
 z.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/z.sh b/z.sh
index c2036c6..542e3fb 100644
--- a/z.sh
+++ b/z.sh
@@ -34,6 +34,10 @@ _z() {
     # if symlink, dereference
     [ -h "$datafile" ] && datafile=$(readlink "$datafile")
 
+    # if datafile parent directory doesn't exist, create it
+    local datapath=$(dirname "$datafile")
+    [ -d "$datapath" ] || mkdir -p "$datapath"
+
     # bail if we don't own ~/.z and $_Z_OWNER not set
     [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return