3

I prefer to use readline instead of editline in the Python REPL and MySQL for example. These programs are compiled with editline support as provided by Apple or Homebrew. How can I make them work with readline instead?

1 Answer 1

3

From my GitHub Discussions post:

Use readline instead of editline (MacOS)

These instructions should work in other Unix-like/Linux OSes in addition to MacOS.

Disable editline

Edit ~/.editrc and decide what to remove. Then add:

edit off

or prefix it with the application name or regex to limit which ones have editline disabled:

python3:edit off

The only line I previously had in that file was bind -e which I removed.

You can provide multiple prefixed lines (or an appropriate regex) to have the command apply to additional applications.

Install rlwrap

brew install rlwrap

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

rlwrap --help

or the man page.

Edit ~/.inputrc

If you need to make any changes or additions to readline bindings you can edit this file. If you want to have configurations for particular programs wrap the settings in $if conditionals.

For system-global configuration, use /etc/inputrc. But note that a user-local configuration completely overrides the global one instead of being preferentially merged. However, you can include the global file (or others) using $include. Placement of those lines within a file controls precedence.

Create aliases

In your ~/.zshrc or ~/.bashrc or other startup files (depending on how your shell is started), create aliases to make the use of rlwrap more convenient. For example:

alias python3='rlwrap python3'

I keep my aliases in a separate file and source them in my main startup file. I use ~/bin/aliases but ~/.aliases is another suggestion.

You can also run programs on an ad-hoc basis without an alias by prefixing the program name with rlwrap followed by a space (but without the surrounding quotes seen in the alias command).

Adjust your history files

For example, my Python history file was ~/.python_history but the one created after using rlwrap is ~/.python3_history. Instead of changing some configuration, I just renamed my old history so I could continue to use it:

mv ~/.python_history  ~/.python3_history

Enjoy!

Ctrlryour-previous-command

And that's not all...

Try it with MySQL and others, too!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .