Term::ReadLine::Gnu vs. history controlby madscientist (Novice)
|on Dec 06, 2012 at 00:34 UTC||Need Help??|
madscientist has asked for the
wisdom of the Perl Monks concerning the following question:
I'm so frustrated with the Term::ReadLine::Gnu module: I don't know whether it's the Perl implementation or the underlying readline library functionality but it's making me crazy.
What I need is to have a standard readline-enabled script, BUT I must be able to remove some entries from the history. For example if someone enters a command with a password I need to be able to take that out and rewrite it with a version that hides the password, so the password is not left in the history file.
I'm absolutely bonkers trying to get this to work. Ideally there would be a way to have readline() simply not add anything to the history, and then I'd call addhistory() myself when I wanted. However that doesn't appear to be possible.
So then I tried to use remove_history(where_history()) to remove the last entry from the history. But first, the history position is not set when you invoke ReadHistory(); it's left at 0; readline() will set it but I don't always invoke readline() (sometimes the commands are given non-interactively, on the command line, but I still want them in the history). So I had to call history_set_pos(scalar(GetHistory())) to force it to be set to the end of the history.
But even then, remove_history(where_history()) doesn't work; the entry still appears in the history and the next readline() will move you past it again.
Please, great Monks! Can you tell me how to disable automatic history adding in Term::ReadLine::Gnu, or if not, give me some hints as to how to manipulate the history in a reliable way! My history can be very large (1000 entries) and so completely recreating it at every prompt is not something I'm too excited about :-/