[MacPorts] #56381: It would be nice if shell mode saved command history immediately
MacPorts
noreply at macports.org
Sat Jun 2 07:41:36 UTC 2018
#56381: It would be nice if shell mode saved command history immediately
----------------------------+--------------------
Reporter: ylluminarious | Owner: (none)
Type: enhancement | Status: new
Priority: Normal | Milestone:
Component: base | Version: 2.4.3
Resolution: | Keywords:
Port: |
----------------------------+--------------------
Comment (by ylluminarious):
Replying to [comment:9 raimue]:
> Indeed, if libedit does not implement `append_history` that is really
unfortunate. Looks like it was only [https://gnats.netbsd.org/cgi-bin
/query-pr-single.pl?number=51518 recently added] to NetBSD, which would be
where Apple borrowed their implementation, but it has also been patched
since the initial import. It is unlikely that this will find its way into
macOS, definitely not into older releases. Filing a
[http://bugreport.apple.com/ rdar] might help.
Yes, you're right. While fishing around for ideas, I found the original
source of libedit and it seems that Apple has not made many changes to
their distribution of it over the years. I doubt they would help even
after filing a rdar... I'm very doubtful that they'd backport old releases
of macOS which are no longer supported.
----
> Not sure how we want to continue with this, then. Do we want to roll our
own code to manage the history file? I have doubts that this is worth
importing the whole libedit source to our vendor libraries...
Yes, importing the whole of libedit is not worth this one feature. I'd
agree that to do so would be overkill. All of this has led me to the
conclusion that we need to roll our own solution or drop the whole issue
entirely. I prefer the former, so I've come up with a rather simplistic
solution which may actually suffice.
I poked and prodded around Apple's sources, NetBSD's sources, and finally
the GNU info manual for their History library and I finally wrote a few
lines which actually seem to do the job. The key was that I found the
{{{current_history()}}} function which yields the most recent history
item. Its return value can be used to access the raw string via the
{{{line}}} field. I.e., {{{current_history()->line}}}
After finding this function, I wrote a couple of lines with just
{{{fopen}}} and {{{fprintf}}} and it seems to work. The code is very
basic; there's no error-handling on I/O errors and there's no
encoding/decoding of the history string. However, it seems that such en
/de-coding is **not** necessary. This surprised me at first, until I
realized that macOS's {{{bash}}} is also using Readline (I think) and it
has no such encoding wherein the space character is translated to
{{{\040}}} and so forth.
Readline seems to be able to pull history items out of the list even if
they are using raw whitespace, without any hitch whatsoever. I tried also
to send lines with lots of different characters such as braces,
semicolons, ampersands, and all kinds of stuff and Readline did not so
much as hiccup. I'm surprised and I'm hoping that this code is sufficient
to solve this issue. Please let me know what you think and if you have any
improvements in mind.
Thanks.
--
Ticket URL: <https://trac.macports.org/ticket/56381#comment:10>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list