terminal – How can I exploit readline as an alternative of editline within the Python REPL and different applications?

terminal – How can I exploit readline as an alternative of editline within the Python REPL and different applications?

From my GitHub Discussions post:

Use readline as an alternative of editline (MacOS)

These directions ought to work in different Unix-like/Linux OSes along with MacOS.

Disable editline

Edit ~/.editrc and determine what to take away. Then add:

edit off

or prefix it with the applying identify or regex to restrict which of them have editline disabled:

python3:edit off

The one line I beforehand had in that file was bind -e which I eliminated.

You may present a number of prefixed strains (or an acceptable regex) to have the command apply to extra purposes.

Set up rlwrap

brew set up rlwrap

rlwrap has a bunch of choices, see the output of:

rlwrap --help

or the man page.

Edit ~/.inputrc

If it’s worthwhile to make any adjustments or additions to readline bindings you’ll be able to edit this file. If you wish to have configurations for explicit applications wrap the settings in $if conditionals.

For system-global configuration, use /and so forth/inputrc. However word {that a} user-local configuration utterly overrides the worldwide one as an alternative of being preferentially merged. Nonetheless, you’ll be able to embrace the worldwide file (or others) utilizing $embrace. Placement of these strains inside a file controls priority.

Create aliases

In your ~/.zshrc or ~/.bashrc or different startup recordsdata (relying on how your shell is began), create aliases to make the usage of rlwrap extra handy. For instance:

alias python3='rlwrap python3'

I preserve my aliases in a separate file and supply them in my predominant startup file. I exploit ~/bin/aliases however ~/.aliases is one other suggestion.

You may as well run applications on an ad-hoc foundation with out an alias by prefixing this system identify with rlwrap adopted by an area (however with out the encompassing quotes seen within the alias command).

Alter your historical past recordsdata

For instance, my Python historical past file was ~/.python_history however the one created after utilizing rlwrap is ~/.python3_history. As an alternative of adjusting some configuration, I simply renamed my outdated historical past so I might proceed to make use of it:

mv ~/.python_history  ~/.python3_history

Get pleasure from!

Ctrlryour-previous-command

And that is not all…

Strive it with MySQL and others, too!

Leave a Reply

Your email address will not be published. Required fields are marked *