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.
284
questions
2
votes
0
answers
144
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
2
answers
14k
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
1
answer
91
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\"...
5
votes
1
answer
742
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.
...
14
votes
2
answers
955
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
1
answer
91
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 ...
4
votes
3
answers
426
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.
...
2
votes
1
answer
157
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
1
answer
39
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
2
answers
273
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 ...
3
votes
1
answer
1k
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
1
answer
252
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 ...
2
votes
1
answer
310
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
1
answer
163
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:
...
2
votes
1
answer
100
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
0
answers
1k
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-...
5
votes
0
answers
210
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 ...
-1
votes
2
answers
300
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
1
answer
983
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 ...
2
votes
1
answer
291
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
...
2
votes
0
answers
243
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
1
answer
83
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 ...
0
votes
0
answers
407
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 ...
3
votes
2
answers
4k
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
1
answer
1k
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
1
answer
888
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
1
answer
762
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 ...
3
votes
2
answers
271
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
0
answers
696
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 $...
4
votes
1
answer
1k
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
1
answer
1k
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
1
answer
459
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
2
answers
418
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
2
answers
354
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 (...
6
votes
4
answers
3k
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
1
answer
887
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/...
0
votes
0
answers
490
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 ...
8
votes
1
answer
550
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
1
answer
221
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 ...
3
votes
1
answer
1k
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 ...
1
vote
1
answer
313
views
How do I tell readline to use an updated .inputrc?
I have updated my ~/.inputrc file to test out show-all-if-unmodified, and now want to try it out. How do I use it without logging off and back in?
3
votes
0
answers
2k
views
gcc: readline/libreadline.a: No such file or directory gcc: readline/libhistory.a: No such file or directory
I am trying to install python readline 6.2.4.1 package on SLES 11 SP3 but I am getting the following error:
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -...
3
votes
0
answers
374
views
Redo not working correctly for (readline) `vi` command-line editing
I'm using vi command-line editing:
shopt -o -s vi
My problem is that while undo (u) works as expected, that is not true redo (.).
In particular, if I've the following command-line AA BB CC, then ...
1
vote
1
answer
84
views
"i" key is not functional in bash
In bash, the key that normally outputs the i character, stays dead. It does not output anything, no space no character, multiple keystrokes of same key do neither.
This is happening on trisquel8, out ...
1
vote
1
answer
525
views
How do I use bind (or .inputrc) to map two bash commands to one key?
Normally, I use vi mode in bash. It starts off in insert mode you have to hit Esc (or Altj was it?) to get into normal (command) mode.
I also bind ↑ (up-arrow) to history-search-backward.
What ...
-2
votes
1
answer
550
views
What does `bind '"\C-i": menu-complete'` do?
I would like to fill out a command which expects a file argument, by alternating the files in the current directory. So I followed Gilles' reply
Bind the Tab key to the
menu-complete
command ...
11
votes
5
answers
9k
views
Alternative to Ctrl-R reverse search in bash
I am happy and really like the Ctrl-R backward search feature of the bash shell. Some of my colleagues don't like it, since it is sometimes confusing. I understand them. If you enter the wrong ...
1
vote
1
answer
1k
views
Bash not loading inputrc automatically
No matter what I try I can't get bash to load my ~/.inputrc file. The most minimal example I have tested is getting rid of my ~/.bashrc and then having a single line in my ~/.inputrc with
set ...
1
vote
1
answer
490
views
Readline: using tab as menu-complete, how do I “accept” the auto-completed directory and display the next level down?
I'm using the following settings on my readline (~/.inputrc):
set show-all-if-ambiguous on
set menu-complete-display-prefix on
set completion-ignore-case on
"\t": menu-complete
"\e[Z": menu-complete-...
2
votes
1
answer
107
views
how to detect state of bash readline using bash script?
for example;
if [ 'readline is vi-command' ]; then
echo 'normal mode'
else
echo 'insert mode'
fi
I really don't have any idea how to do this and I can't seem to find anything on the man pages ...