terminal – How can I take advantage of readline as a substitute of editline within the Python REPL and different applications?


From my GitHub Discussions submit:

Use readline as a substitute 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’ll be able to present a number of prefixed traces (or an acceptable regex) to have the command apply to further functions.

Set up rlwrap

brew set up rlwrap

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

rlwrap --help

or the man web page.

Edit ~/.inputrc

If it’s essential make any modifications or additions to readline bindings you may 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 fully overrides the worldwide one as a substitute of being preferentially merged. Nonetheless, you may embrace the worldwide file (or others) utilizing $embrace. Placement of these traces inside a file controls priority.

Create aliases

In your ~/.zshrc or ~/.bashrc or different startup information (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 fundamental startup file. I take advantage of ~/bin/aliases however ~/.aliases is one other suggestion.

It’s also possible to 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 information

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

mv ~/.python_history  ~/.python3_history

Get pleasure from!

Ctrlryour-previous-command

And that is not all…

Attempt it with MySQL and others, too!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles