Hot answers tagged readline
52
Ctrl-Q is indeed the answer. I thought I'd toss in a little history of this that is too long to fit in the margins of ak2's correct answer.
Back in the dark ages, a terminal was a large piece of equipment that connected to a remote device (originally another terminal because teletypes were so much easier to learn to operate than a telegraph key) over a long ...
11
By setting your readline editing to either emacs (the default) or vi (set -o vi) you are essentially standardizing your editing commands, across the shell and your editor of choice1.
Thus, if you want to edit a command in the shell you use the same commands2 that you would if you were in your text editor. This means only having to remember one command ...
7
This line is your problem
/# do not bell on tab-completion
If I add that line to my working config, slash stops working.
The only clue that I can find about this is in the readline man page:
Blank lines are ignored. Lines beginning with a # are
comments. Lines beginning with a $ indicate conditional constructs. Other lines denote key ...
7
Use the Dotdeb Debian stable packages. Although the documentation does not note this, the stable packages currently work fine with Wheezy/testing. After following the instructions, do:
apt-get install php5-cli
as root.
7
To do literally what you're asking, put the following line in your ~/.inputrc:
"\e\e[A": "cd ..\n"
Here \e\e[A is byte sequence that your terminal sends when you press Alt+Up (\e is parsed as the escape character), some terminals might send \e[1;3A~ or some other sequence instead. To find out what sequence your terminal sends, run cat and press the key ...
7
You can use rlwrap for this, if you don't mind installing software.
You'll probably want to keep a separate history file that only maintains history for the particular prompt in your script (ie. avoid mixing with the user's shell command history).
Here's an example that might work for you:
#!/bin/sh
# Save in rlwrap_example.sh
...
7
It goes into a kill-ring, just like in Emacs. From the GNU Readline docuementation:
When you use a kill command, the text is saved in a kill-ring. Any
number of consecutive kills save all of the killed text together, so
that when you yank it back, you get it all. The kill ring is not line
specific; the text that you killed on a previously typed ...
6
This is actually your terminal doing something weird, not Vim. Terminals have two sets of control sequences associated with cursor keys, for historical reasons: one for full-screen applications, often called “application cursor keys mode”, and one for read-eval-print applications (e.g. shells).
In the old days, read-eval-print applications didn't have any ...
5
You need to remove whitespace characters from the $IFS parameter for read to stop skipping leading and trailing ones (with -n1, the whitespace character if any would be both leading and trailing, so skipped):
while IFS= read -rn1 a; do printf %s "$a"; done
But even then bash's read will skip newline characters, which you can work around with:
while IFS= ...
5
As in your example, you can use next construction:
mv foo/bar/poit/zoid/{narf.txt,troz.txt}
or even (as suggested Ansgar Esztermann):
mv foo/bar/poit/zoid/{narf,troz}.txt
instead ot typing/copypasting long address twice.
5
For hysterical historical reasons. Hardware manufacturers didn't always standardize on common single control sequence for the same key, and neither did software writers when glass terminals were replaced by terminal emulators.
You can find out what control sequence a key generates in a particular terminal by typing Ctrl+V then the key (in most shells, or in ...
4
I'm not sure if there is a direct advantage. I've been a vi user for more than 20 years. I'm also a screen user for even longer, and of other programs that use vi keys. It's natural for me to prefer to set "vi" mode in bash. But I also work on hundreds of servers in my job, most are set to the default "emacs" mode. So I need to use both modes. But it ...
3
So after digging around some more, I found whats going on. RHEL5's build of bash doesnt use terminfo at all (why, who knows, its redhat), it uses termcap. However there is apparently another bash on the box which does use terminfo. This is why subshells and re-execing would work, as they would use the other bash, not the default one. I feel stupid for not ...
3
The main advantage is modal editing of your command line. If you're familiar with Vim and likes its philosophy the benefits must be obvious. If you are experienced with it, your finger's muscle memory will make you edit your bash commands in lightning speeds.
NB: If you don't like modal editing, you should still learn to take advantage of the (default) ...
3
The short answer is no, I'm pretty sure no such program exists.
You could in principle build one; it would have to look at the readline configuration and at the terminal emulator (the kernel and hardware are not involved).
bind -P | grep 'can be found' in Bash lists the key bindings.
abort can be found on "\C-g", "\C-x\C-g", "\e\C-g".
accept-line can be ...
3
According to the freetalk documentation, it uses GNU Readline for its line editing features.
According to the GNU Readline documentation:
In order to switch interactively
between emacs and vi editing modes,
use the command M-C-j (bound to
emacs-editing-mode when in vi mode and
to vi-editing-mode in emacs mode). The
Readline default is emacs ...
3
Keybinding can be done using one of the following forms:
keyname: command_name
"keystroke_sequence": command_name
In first form you can spell out the name for a single key. For example, CONTROL-U would be written as control-u. This is useful for binding commands to single keys.
In the second form, you specify a string that describes a sequence of keys ...
3
Readline doesn't know anything about a modifier called Shift, and quietly ignores unknown modifier names. Try wibble-TAB.
To bind an action to Shift+Tab, you need to find out what escape sequence your terminal sends. In bash, run cat and type Ctrl+V then Shift+Tab. This will insert the escape sequence literally. It's likely that the first character will be ...
3
In a path, it's quite easy, dirname takes off the last component of the path. And since it's a program (as opposed to a builtin) it's completely portable between shells.
$ dirname /usr/local/bin
/usr/local
It appears you mean while editing an active line at the prompt. In that case Nikhil's comment of esc backspace (consecutively, not both at the ...
3
The set command in the readline manual is the one in readline's configuration file, ~/.inputrc. Although bash is the most famous user of the readline library, the library is generic and can be used by other programs; the syntax of .inputrc is unrelated to bash.
You can make bash execute readline commands through the bind builtin:
bind "set var value"
...
3
As an addition to the answer by Gilles who suggest recompiling the complete PHP package you can also wait for PHP 5.4. In 5.4 I restructured the realdine functionality that all required parts are in the readline module, so you can built that stand alone.
$ wget ...php-5.4.0.tar.bz2
$ tar xjf php-5.4.0.tar.bz2
$ cd php-5.4.0/ext/readline
$ phpize && ...
3
The readline commands that you are looking for are the history-search-* commands:
history-search-forward
Search forward through the history for the string of characters between the start of the current line and the current cursor position (the point). This is a non-incremental search.
history-search-backward
Search backward through the history for the ...
2
Install rlwrap and run rlwrap php5. Rlwrap is a generic readline wrapper, it provides command line edition and history for any read-eval-print loop. Since it's a generic wrapper, you won't get any PHP-specific completion.
Alternatively, get the source package and rebuild it with readline support. Readline support was only left out due to licensing issues, ...
2
In brief, add the following lines to ~/.inputrc:
"\ew": kill-region
"\ea": '\e \C-] \ew'
where w and a characters could be changed to your will.
How does it work
Let's assign a key sequence to the kill-region readline command, for example Alt-w
"\ew": kill-region
then let's assign the following macro to another sequence, say Alt-a:
"\ea": '\e \C-] ...
2
This is the same question I asked I while back, so I'm not taking credit for this, but I had to put
xterm*metaSendsEscape: true
URxvt*altSendsEscape: true
in .Xresources to make Alt work as Meta in both xterm and urxvt. It is a bit contradictory, but it works. So experiment with those options. Also, I had to put
xrdb ~/.Xresources
in .xinitrc for it to ...
2
If I've planned ahead, I use brace expansion. Here is another approach using the default readline keyboard shortcuts:
mv foo/bar/poit/soid/narf.txt: start
Ctrl-w: unix-word-rubout to delete foo/bar/poit/soid/narf.txt
Ctrl-ySpaceCtrl-y: yank, space, yank again to get mv foo/bar/poit/soid/narf.txt foo/bar/poit/soid/narf.txt
Meta-backspaceMeta-backspace: ...
2
In a comment to your question you say that you are so accustomed to vim.
In this case you probably don't like working with long statements in vim's command-line mode. I don't like it either.
Thankfully we can edit command's not only in the command line but also in the command-line window. You can open it with q:. After the window opened you have access to ...
2
Bash has readline commands that aren't bound by default. You can find them at reference: http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands
Command you are looking for is called "shell-backward-kill-word". You have to select shortcut first. Let's use Crtl+p, since it's "previous command" - same as up ...
2
The dir file is automatically generated/expanded by install-info and contain information about the available documentation of the texinfo documentation system.
You can simply delete this file. If you want to use info system, you can try to merge the dir into the other before. Or you can run a install-info command (e.g. install-info --info-dir=$PWD ...
1
This is a simple example using cut, a for loop & wc :
bytes=$(wc -c < /etc/passwd)
file=$(</etc/passwd)
for ((i=0; i<bytes; i++)); do
echo $file | cut -c $i
done
KISS isn't it ?
Only top voted, non community-wiki answers of a minimum length are eligible


