Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Term::ReadLine::Gnu vs. history control

by madscientist (Novice)
on Dec 06, 2012 at 00:34 UTC ( #1007439=perlquestion: print w/replies, xml ) 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 :-/

  • Comment on Term::ReadLine::Gnu vs. history control

Replies are listed 'Best First'.
Re: Term::ReadLine::Gnu vs. history control
by LanX (Bishop) on Dec 06, 2012 at 01:39 UTC
    works for me!
    use Term::ReadLine; $term = new Term::ReadLine 'ProgramName'; print "Using: ", $term->ReadLine, "\n"; # is Gnu install +ed? $|=1; $term->MinLine(); while ( defined ($_ = $term->readline('prompt>')) ) { print "$_\n"; next if (/not/); $term->AddHistory($_); }

    Using: Term::ReadLine::Gnu prompt>a a prompt>not b not b prompt>a a

    a was in history, b was not.

    Cheers Rolf

Re: Term::ReadLine::Gnu vs. history control
by LanX (Bishop) on Dec 06, 2012 at 01:11 UTC
    your not showing code and the docs are full of hits for "history"

    see AddHistory(LINE1, LINE2, ...), MinLine([MAX]), autohistory, Features,... and so on to disable autohistory and adding manually to it.

    if this doesnt help plz show us some code to reproduce what you're doing.

    Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007439]
Approved by LanX
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-10-20 11:00 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (117 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!