Questions tagged [readline]
GNU Readline is a library that provides command-line editing and history searching capabilities for Bash and other interactive command-line programs. Use this tag for questions relating to the use of Readline functionality in Bash and other software.
245
questions
1
vote
0answers
14 views
How to have `SPACE: magic-space` in ~/.inputrc without breaking Python 3 REPL?
If I put SPACE: magic-space in my ~/.inputrc file for configuring Readline, then I cannot enter SPACEs in python3 REPL (v3.8.7)
How can I use SPACE: magic-space in my ~/.inputrc without breaking ...
0
votes
0answers
24 views
How do I use an alternative history file with reverse-search-history in ~/.inputrc?
I am trying to keep two command history files:
one for the local session only, so that arrows up and down only navigate
through the history of the current bash session
one common for all sessions, so ...
0
votes
1answer
34 views
How to use “\M-\C-” as an key sequence prefix when defining key bindings using Readline in Bash?
If I put "\M-\C-k": kill-whole-line in my ~/.inputrc file the result is "\213": kill-whole-line (displayed by bind -p).
However, if I change \M- to \e ("\e\C-k": kill-...
1
vote
1answer
53 views
Bash _/- completion
man bash says:
completion-map-case (Off)
If set to On, and completion-ignore-case is enabled, readline treats hyphens (-) and underscores (_) as equivalent when performing case-insensitive ...
0
votes
0answers
16 views
How to run an interactive (dynamic) program like htop from another program in the terminal and actually see it?
I run a readline application. I would like to call interactive programs from it, like htop, and see them. I can call them, with my programming language of choice, but the program doesn't show up. It ...
0
votes
1answer
39 views
Expand shell variable while editing command line
If I write ls bla.* at the prompt and then I press = while the cursor is still on the bla.* part of the command line, the list of files matching bla.* is printed. If I press *, that word is ...
0
votes
1answer
13 views
readline's rl_parse_and_bind causes crash
I am using Ubuntu 18.04.5. This very simple program segfaults on the invocation of rl_parse_and_bind. Can anyone help me?
// Build with cc read.c -o read -lreadline
#include <readline/readline.h&...
0
votes
0answers
21 views
Redo in readline emacs editing mode
How to redo (or undo an undo) in readline Emacs editing mode?
The ways I've found for Emacs (C-g _) do not seem to work from the command line.
0
votes
2answers
108 views
Syntax error near unexpected token “done”— while read line
I keep getting this error: syntax error near unexpected token 'done' but I don't understand why.
I tried adding dos2unix *.sh after #!/bin/sh, but that just gave me an error that said no such file or ...
0
votes
1answer
11 views
readline in a C program obeys history-search-backward and history-search-forward
I would like to use readline in a C program, with history-search-backward and history-search-forward triggered by the up and down arrows. I tried things like
rl_parse_and_bind("\"\e[A\"...
1
vote
1answer
28 views
Accept all tab-completion suggestions to a command
To edit file1, file2, file3, ... in the current directory, I can issue
vi file*
and the shell will take care of expanding the pattern.
That is fine for operating on files. But consider the following ...
5
votes
1answer
120 views
Does zsh use canonical-mode for the terminal?
I have been exploring terminfo and stty.
If I run stty -a|grep icanon it appears that canonical mode is set, but if I try to turn it off with stty -icanon and check again, I see that it is still set.
...
12
votes
2answers
479 views
Is it possible to save `bc` command line history?
bash has a handy file .bash_history in which it saves the history of commands and on the next execution of bash the history is populated with saved commands.
Is it possible to save bc command history ...
0
votes
1answer
31 views
How to assign control n to bind any readline function
Tried to assign control n to bind any readline function in bash but can't, e.g:
bind '"\C-n" : previous-history'
but still work as bind -x '"\C-n" : "echo foo"'
Why and ...
2
votes
3answers
55 views
Run command and keep editing it in Bash
return runs command and clears the command line. Is it possible to skip the clear part? So the command is executed but command line and cursor position is preserved so you can keep editing it.
...
1
vote
1answer
22 views
How can I add a hot-key to readline for zsh or bash that takes fills in the 2nd parameter to copy but with .bak?
I'd like to make a hot-key for this task I sometimes need to perform:
%> cp file.txt.1 file.txt.1.bak
Where I've repeated the file name but with a .bak on the end. I'd like to instead just type:
%...
3
votes
1answer
28 views
How to execute ctrl+r query as-is instead of a match?
Sometimes when I reverse-search cmd in a shell I don't find a correct match and just want to execute search query as it is.
Is there a way in bash/zsh and friends to execute it without discarding ...
7
votes
1answer
103 views
Insert the last argument in bash in vi mode without inserting a leading space
Using bash in the default (emacs) mode I get the following behavior when I hit Esc,āÆ..
$ echo hello
hello
$ hello # I hit `<ESC>.` to insert this
Note there is no space before the word hello ...
1
vote
1answer
63 views
Tmux behaves differently and C-a + C-a prints “^A” instead of jumping to beginning of line
I have the following entries in my ~/.tmux.conf
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
which usually have been sufficient to use tmux with ...
2
votes
1answer
23 views
How can I supply a numeric argument to a Readline function e.g. `glob-expand-word`?
How can I supply an argument to a Readline function, e.g. glob-expand-word that is bound to C-x * by default?
In this case, I want to supply a numeric argument to make append an asterisk to the word ...
0
votes
0answers
21 views
yank-last-arg with numeric argument in vi mode
According to the manual, setting a numeric argument (e.g. Alt-1) and repeatedly invoking Alt-. should keep inserting nth argument from preceding commands. For example, issuing
echo arg1 arg2
echo ...
3
votes
1answer
108 views
Bash expansion behavior
I was playing around with the readline functions shell-expand-line and alias-expand-line.
From the documentation:
shell-expand-line Expand the line as the shell does. This performs
alias and ...
0
votes
1answer
37 views
Customizing scrollback buffer navigation keys
I am using a VTE based terminal. By manually sending the following command in a bash session, I see the scrollback buffer moving up by one line, so I am pretty confident the escape sequence is right:
...
1
vote
1answer
41 views
Why does bash print the debug trap after edit-and-execute-command
I've found a behavior in bash (or is it readline?) that I cannot explain. After invoking the edit-and-execute-command Readline command, the debug trap's command is printed prior to execution. Is this ...
1
vote
0answers
151 views
How to display the current mode of `vi` command-line editing (`set editing-mode vi`) in bash < 4.3
This question is related to this other one but it is not a duplicate because I need a different solution for a different version of Bash.
I am a regular Vim user and I would like to change my command-...
1
vote
0answers
56 views
On MacOS, what character does `Esc+` or `+Esc` correspond to in Bash, when using iTerm2 terminal?
I've read that mapping Left Option key to Esc+ should fix many of the issues users of Bash, on MacOS, have with GNU Readline key-bindings.
However, I've never encountered Esc+ or +Esc before, so does ...
0
votes
2answers
68 views
How to insert an entire command from history into the current command in Bash?
How to insert an entire command from history into the current command in Bash?
I've done some research and identified two GNU Readline key-bindings that would insert the first and last words of the ...
2
votes
1answer
243 views
bash: Is there a way to invoke bind commands (e.g. redraw-current-line) programmatically?
I've come across a number of explanations on how to map redraw-current-line to a keystroke using bind, but I would like to redraw the prompt for other reasons (e.g. timer, background job), without the ...
1
vote
1answer
104 views
Use bash builtin `bind` command when starting chroot
I have a chroot and I want the chroot to have its own .inputrc file when it starts, and then run a program.
I'm used to starting the chroot with chroot <PATH> <PROGRAM_TO_RUN> so I tried
...
0
votes
0answers
88 views
Bash autocomplete: list files and cycle through them
Trying to achieve the behavior mentioned in the posts below: make bash list the suggestions (like it does by default, as TAB is set to complete), but also cycle through suggestions on concurrent tabs. ...
1
vote
0answers
65 views
change global GNU readline history location
I was able to change the history location of some tools via envvars, e.g.:
export PYTHONHISTFILE=/tmp/.python_history
export NODE_REPL_HISTORY=/tmp/.node_repl_history
export REDISCLI_HISTFILE=/tmp/....
0
votes
1answer
54 views
Using bind breaks shell
(WSL with Ubuntu 18.04)
I have some configuration settings that I have used before and that can be seen recommended in various places across the internet (not to mention on SO). I hav placed them in ...
1
vote
0answers
100 views
re-read-init-file action in Bash
I have the following in my .inputrc file:
"\C-x\C-r": re-read-init-file
According to the readline man page. this should mean that pressing Ctrl+X, Ctrl+R should reread my .inputrc file. This is what ...
0
votes
0answers
94 views
Complete list of options for .inputrc / readline
I always knew you could switch between Vim and Emacs bindings for Bash by modifying .inputrc.
I'm now realizing there are actually a few different useful options I've decided to turn on including:
...
0
votes
1answer
377 views
Can I rebind Ctrl-C to do the same as ESC in readline?
I have started using vi mode in bash (set -o vi), and my laptop has no escape key (stupid touch barā¦) so its annoying to leave insert mode on the command line. This got me thinking that in Vim, I ...
0
votes
1answer
248 views
How do I remap function keys in readline bash vi (vi shell mode)?
Regarding mapping function keys in vi readline, I have read these two stackexchanges:
Remap bash vi keys?
Custom key bindings for vi shell mode, ie, "set -o vi"?
I have a MacBookPro with a ...
2
votes
1answer
106 views
Rebinding reverse-search-history in bash
reverse-search-history is bound to C-r by default. One can type C-r to start the search, and then type C-r again to jump to an earlier match.
I have bound reverse-search-history to \er (Alt-r). This ...
2
votes
2answers
88 views
How to bind a key combination to null in .inputrc?
You can bind keys like Ctrl-Left and Ctrl-Right in .inputrc like this:
# Ctrl-Left
"\033[1;5D": backward-word
# Ctrl-Right
"\033[1;5C": forward-word
How would I bind Ctrl-Up and Ctrl-Down to nothing?...
1
vote
0answers
163 views
How to trigger a prompt redraw when the terminal window size changes?
So I created a trap to check if the change is being registered:
trap 'echo $COLUMNS' WINCH
And the change is indeed reflected. But my prompt is not redrawn, neither from re-issuing the $...
2
votes
1answer
341 views
bash readline inputrc: bind key to a sequence of multiple commands
I have shift-tab bound to shell-expand-line in my .inputrc. However, I want shift-tab to also insert a space character after doing the shell-expand-line. How can I do this?
This is what my .inputrc ...
1
vote
1answer
299 views
Read line BASH (Output $line and line below)
I have a question to this read line. I have in my file n lines. How can I store the value in the line below in the same loop step? Can maybe someone help me with that?
Thank you
Details:
$ cat ...
1
vote
1answer
43 views
How to read a file line by line and put them as a variable?
im very new to linux and shell scripting. May I know how do you read a file line by line and pass each line as a variable?
For example, lets say i have a file called abc.txt with these 2 lines as its ...
6
votes
2answers
156 views
Briefly jump to matching parentheses in Bash
In vim there is an option called showmatch. When you type a closing parenthesis in insert mode, this jumps the cursor to the matching opening parenthesis (at the same nesting level), then back again. ...
0
votes
2answers
137 views
Searching command history in any interpreter
By running an interpreter trough rlwrap I have access to the command history by pressing the up and down arrow keys. However, I would like to be able to search the command history like I do in Bash (...
4
votes
3answers
1k views
How to set Readline key bindings using ALT (Meta) or some other control key as prefix instead of `\C-` and `\e`?
I can only find examples of setting Readline key bindings using Control (\C-) or Escape (\e) as prefixes.
In my case, on macOS, the \C- space is completely filled up by default key bindings, and the \...
0
votes
1answer
412 views
Shell script loop while not reading [closed]
I'm trying to figure out the best way to halt a running script using a keyboard shortcut while the terminal is not the active window.
This led me to learn about watching keyboard events with cat /dev/...
1
vote
0answers
118 views
In GNU readline, How to change Alt key to Meta, instead of being ESC?
In GNU readline manual, it says the left Alt is usually Meta:
The Meta key is labeled ALT on many keyboards. On keyboards with two keys labeled ALT (usually to either side of the space bar), the ...
9
votes
1answer
245 views
Why does GNU Readline's shell-expand-line command only expands the first occurrence of tilde (~)?
According to the Bash manual, the shell-expand-line GNU Readline command should expand the command-line, just as Bash normally would, including alias and history expansion.
The current setting can be ...
3
votes
1answer
97 views
How to Set Readline key bindings in both vi-command and vi-insert modes
To use the Emacs transpose-words function in vi mode I have the following .inputrc:
$if mode=vi
bind Control-b: transpose-words
$endif
Unfortunately it only works in "insert" mode. What is the ...
2
votes
1answer
116 views
How to read readline key bindings
bind -P gives me back things like
bracketed-paste-begin can be found on "\e[200~".
revert-line can be found on "\e\C-r", "\er".
previous-history can be found on "\C-p", "\eOA", "\e[A".
How do I ...