From 9a12fd80213c985fc91ee75854918523106377f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= <p@janouch.name>
Date: Tue, 29 Sep 2020 00:55:01 +0200
Subject: Add ability to run helpers externally

So far experimental and essentially undocumented.
---
 README.adoc | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

(limited to 'README.adoc')

diff --git a/README.adoc b/README.adoc
index e49cbce..5ca0e5f 100644
--- a/README.adoc
+++ b/README.adoc
@@ -52,9 +52,11 @@ To start using this navigator, put the following in your .zshrc:
 ....
 sdn-navigate () {
   # ... possibly zle-line-init
-  eval "`sdn`"
-  [ -z "$cd" ] || cd "$cd"
-  [ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
+  while eval "`sdn`"; do
+    [ -z "$cd" ] || cd "$cd"
+    [ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
+    [ -z "$helper" ] && break
+    eval "exec </dev/tty; $helper" || break
   zle reset-prompt
   # ... possibly zle-line-finish
 }
@@ -65,19 +67,22 @@ bindkey '\eo' sdn-navigate
 bash
 ----
 Here we can't reset the prompt from within a `bind -x` handler but there is
-an acceptable workaround:
+an acceptable workaround that sadly submits a blank line:
 
 ....
 sdn-navigate () {
   SDN_L=$READLINE_LINE SDN_P=$READLINE_POINT
   READLINE_LINE=
 
-  eval "`sdn`"
-  [[ -z "$cd" ]] || cd "$cd"
-  [[ -z "$insert" ]] || {
-    SDN_L="${SDN_L:0:$SDN_P}$insert ${SDN_L:$SDN_P}"
-    ((SDN_P=SDN_P+${#insert}+1))
-  }
+  while eval "`sdn`"; do
+    [[ -z "$cd" ]] || cd "$cd"
+    [[ -z "$insert" ]] || {
+      SDN_L="${SDN_L:0:$SDN_P}$insert ${SDN_L:$SDN_P}"
+      ((SDN_P=SDN_P+${#insert}+1))
+    }
+    [[ -z "$helper" ]] && break
+    eval "$helper" || break
+  done
 }
 sdn-restore () {
   READLINE_LINE=$SDN_L READLINE_POINT=$SDN_P
-- 
cgit v1.2.3

