Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: %! prompt code shows incorrect number



On 5/17/21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sun, May 16, 2021 at 9:49 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> Perhaps we could import events as numbers that are unused instead of
>> overriding the number we have told the user is going to be used for
>> the command they run?
>
> Then the events would be out of order, which sort of ruins the
> "incremental" part.
>
> I don't think there's any simple fix here.  Possibly reprint the
> prompt at (approximately) preexec time to show the correct number?

I've gone with the below hack for now. What I want to be able to do is
copy the history number from the prompt and paste it back into the
terminal, and have my paste handler grab the corresponding entry from
$history and paste it into the prompt for me. With the hack I can
simply add "l" to this query and it seems to work as I want... I'm not
submitting this for inclusion, just as is.

I don't think there's any existing way to check if a history entry is
external other than parsing the * out of fc -l output?

diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index ef9148d7b6..6c73daf557 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -1158,6 +1158,7 @@ getpmhistory(UNUSED(HashTable ht), const char *name)
     Histent he;
     const char *p;
     int ok = 1;
+    int local = 0;

     pm = (Param) hcalloc(sizeof(struct param));
     pm->node.nam = dupstring(name);
@@ -1169,13 +1170,18 @@ getpmhistory(UNUSED(HashTable ht), const char *name)
 	    ok = 0;
 	else {
 	    for (p = name; *p && idigit(*p); p++);
-	    if (*p)
+	    if (p[0] == 'l' && !p[1])
+		local = 1;
+	    else if (*p)
 		ok = 0;
 	}
     }
-    if (ok && (he = quietgethist(atoi(name))))
+    if (ok && (he = quietgethist(atoi(name)))) {
+	if (local && (he->node.flags & HIST_FOREIGN)) {
+	    while ((he = down_histent(he)) && (he->node.flags & HIST_FOREIGN));
+	}
 	pm->u.str = dupstring(he->node.nam);
-    else {
+    } else {
 	pm->u.str = dupstring("");
 	pm->node.flags |= (PM_UNSET|PM_SPECIAL);
     }


-- 
Mikael Magnusson




Messages sorted by: Reverse Date, Date, Thread, Author