1. 15

  2. 14

    There’s also rlwrap for the occasional interactive utility that doesn’t support all these familiar keybindings.

    1. 1

      +1 for rlwrap. Back when I had to use the oracle cli I praised the day that I discovered it.

    2. 9

      And if you don’t like the GPL that much, there’s:

      • A portable version of NetBSD’s libedit.
      • antirez (of Redis fame)’s linenoise if you just want to drop a single C source code file in.
      • linenoise-ng, which actually has UTF-8 support, too, but requires a C++ compiler and consists of more than one source code file; it does expose a C interface, though.
      1. 2

        I don’t like replacement because they always fail to implement something or other about GNU readline. For example, Ctrl-o is one of my favourite keybindings. You use Ctrl-r to search back in history, and then successively hit C-o to replay history from the search point. This feature is obscure and almost never duplicated in replacements.

      2. 9

        Something interested I learned while working on a shell: GNU readline was extracted from bash, while curses was at least partly extracted from vi!

        In other words, the libraries were extracted from applications, rather than written from the ground-up as libraries. That seems to be a more fool-proof way to design a complete and usable (if not optimal) interface.


        1. 1

          Huh, I always thought curses was written from whole cloth for rogue?

          1. 1

            Hm yeah it’s possible I misread / overstated. The wikipedia says that vi predates curses, and some code in curses was borrowed from vi. But I guess it’s also true that rogue was the first application that used curses?

            Sometimes it is incorrectly stated that curses was used by the vi editor. In fact the code in curses that optimizes moving the cursor from one place on the screen to another was borrowed from vi, which predated curses

            The first curses library was written by Ken Arnold and originally released with BSD UNIX, where it was used for several games, most notably Rogue

        2. 8

          @NinjaTrappeur is there something specific you’d like to relate about Readline?

          1. 8

            Yes, this C library is actually used by a lot of CLI utilities (zsh, bash, …), making all the keybinding listed in this Wikipedia article available in a lot of programs.

            For example, the Ctrl-_, Alt-l are actually really useful in a shell context.

            It is maybe common knowledge, but I just discovered that recently. I though it may be useful for some other people. I was apparently wrong.

            I have trouble understanding why this is off-topic though.

            1. 13

              I was apparently wrong.

              I’m sure it is interesting to many people, I think it’s hard to understand your intention when you post a random wikipedia page though. Adding a description would probably help people appreciate the contribution more.

              1. 6

                You are right, I’ll try to be more clear when I’ll share similar links in the future. Thanks for this helpful remark.

              2. 5

                zsh does not use readline afaik, it’s mostly used by gtk and glib applications for providing line editing, and other applications that choose to use it. Most of the features readline offers either imitate behaviour specified by the POSIX terminal interface0 or are quality-of-life emacs bindings, so they’re often supported in other software and especially in shells.

                1. 1

                  Aha, you’re right! Thanks for the clarification.

                2. 1

                  I liked it!

              3. 5

                I always thought it interesting how the GNU tools have this split-brain between emacs and vi keybindings. I know that readline (by default) uses emacs, but I believe you’re able to make it use vi-like keybindings instead (or maybe that’s just a feature of Bash?). The two tools I use daily that use vi keybindings are man and less. And then you can see GNU’s influence with info because they use emacs bindings.

                All in all, it’s a pain and I’m a vim guy so beyond single-line editing on the command line, emacs bindings are completely foreign to me. As a result info pages are almost useless to me because I have no idea how to correctly navigate them. ¯\_(ツ)_/¯

                1. 12

                  I believe you’re able to make it use vi-like keybindings instead (or maybe that’s just a feature of Bash?)

                  That’s actually mandated by POSIX, as part of the definition of set for the shell. There was originally a proposal to have an “emacs” mode as well, but as the POSIX rationale document states:

                  In early proposals, the KornShell-derived emacs mode of command line editing was included, even though the emacs editor itself was not. The community of emacs proponents was adamant that the full emacs editor not be standardized because they were concerned that an attempt to standardize this very powerful environment would encourage vendors to ship strictly conforming versions lacking the extensibility required by the community.

                  Gotta love Emacs users ;)

                  1. 2

                    The original FSF crew were all (most?) emacsphiles, according to Brian Fox.

                    Source: many discussions with Brian Fox.

                    1. 1

                      Aw, man, Brian Fox. What’s up with him these days? I wish I could have been there in the early days of the FSF.

                    2. 2

                      …I believe you’re able to make it use vi-like keybindings instead…

                      In ~/.inputrc:

                      set editing-mode vi
                      set keymap vi

                      As a result info pages are almost useless to me because I have no idea how to correctly navigate them.

                      That’s why I install pinfo on every Linux machine I use. It’s still not vi-like bindings, but it’s lynx-like bindings, which are at least easy to learn.

                      1. 1

                        The two tools I use daily that use vi keybindings are man and less.

                        If you’re on some reasonably “normal”-ish Linux distro and haven’t gone out of your way to configure things otherwise, man is most likely just displaying its output via less, so those are kind of one and the same as far as keybindings go – and less actually isn’t a GNU program.

                        1. 1

                          FWIW, less supports both bindings.

                          1. 0

                            info pages

                            Pet peeve. They’re info manuals not pages. Manpages are called that because individually each was supposed to be but a single, one-page cheat sheet of the full Unix manual.

                            The whole point of TeXinfo was to generate full manuals all at once, and in multiple formats, with an index, a table of contents, chapters, menus, and hyperlinks. If you don’t like the text-based info reader, there is HTML and PDF output as well. Use those!

                            … but I know you’ll tell me next, if it’s not in a text-based terminal, you don’t want to read it. In that case, just read the raw .info[.gz] files. They’re plain text files with a few ASCII control characters.

                          2. 4

                            I’ve used the following native Rust (https://github.com/kkawakam/rustyline) and Go (https://github.com/chzyer/readline) libraries to good effect to behave like readline.

                            1. 4

                              TLDR: Most of the keyboard shortcuts here work basically in every software that reads input text.

                              I daily use CTRL+L (clear screen) and CTRL+U (to cut everything before the cursor) in my shell.

                              1. 1

                                I use Ctrl-W (delete previous word) Ctrl-A (go to beginning of line) and Ctrl-R (search previous lines) a lot.

                                1. 2

                                  I used exactly these 15 years long until I discovered that I can switch the VI mode on. Now the first line that I type when logged in on a (foreign) Linux box is “set -o vi”. I hope all terminal REPL applications would use readline so that I could use VI mode line editing everywhere. But that’s not everywhere the case.