+/* @breadcrumbs{DIR}{TEMPLATE}
+ *
+ * Expands TEMPLATE for each directory in the path up to DIR, excluding the root
+ * but including DIR itself, with the following expansions:
+ * - @dir: the directory
+ * - @last: "true" if this is the last directory, otherwise "false"
+ *
+ * DIR must be an absolute path.
+ */
+static int exp_breadcrumbs(int attribute((unused)) nargs,
+ const struct mx_node **args,
+ struct sink *output,
+ void attribute((unused)) *u) {
+ int rc;
+ char *dir, *parent, *ptr;
+
+ if((rc = mx_expandstr(args[0], &dir, u, "argument #0 (DIR)")))
+ return rc;
+ /* Reject relative paths */
+ if(dir[0] != '/') {
+ error(0, "breadcrumbs: '%s' is a relative path", dir);
+ return 0;
+ }
+ /* Skip the root */
+ ptr = dir + 1;
+ while(*ptr) {
+ /* Find the end of this directory */
+ while(*ptr && *ptr != '/')
+ ++ptr;
+ parent = xstrndup(dir, ptr - dir);
+ if((rc = mx_expand(mx_rewritel(args[1],
+ "dir", parent,
+ "last", *ptr ? "false" : "true",
+ (char *)0),
+ output, u)))
+ return rc;
+ if(*ptr)
+ ++ptr;
+ }
+ return 0;
+}
+