bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Negative or zero arguments to yank-last-arg in bound keystrokes


From: Chet Ramey
Subject: Re: Negative or zero arguments to yank-last-arg in bound keystrokes
Date: Mon, 06 Dec 2010 20:22:19 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

On 11/8/10 6:26 PM, Dennis Williamson wrote:

> Bash Version: 4.1
> Patch Level: 9
> Release Status: release
> 
> Description:
> 
> Negative or zero arguments to yank-last-arg in bound keystrokes do not perform
> as expected when the keystroke is pressed repeatedly.
> 
> Comparing to yank-last-arg with no arguments or positive arguments which step
> backwards successively through history entries, when the argument is zero or
> negative, repeated keypresses only alternate between the two previous history
> entries.
> 
> Also present in:
> 
> GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu)
> GNU bash, version 4.0.33(1)-release (i486-pc-linux-gnu)
> GNU bash, version 3.2.51(24)-release (i686-pc-cygwin)
> 
> Repeat-By:
> 
> Create these keystroke bindings using whatever keystrokes you like. The demo
> below will use Alt-h, Alt-i, Alt-j, Alt-k and Alt-m:
> 
>   bind '"\eh": "\e1\e."'
>   bind '"\ei": "\e0\e."'
>   bind '"\ej": "\e-\e."'
>   bind '"\ek": "\e-1\e."'
>   bind '"\em": "\e-2\e."'
> 
> Enter four example commands for testing. It doesn't matter what they are as
> long as they are different commands and have a few arguments that differ so
> it's easy to see the demonstration.
> 
>   printf '%s\n' foo bar
>   echo aaa bbb ccc
>   ls -ld . ..
>   getent passwd root sys
> 
> Press Alt-h four times, you should correctly get "passwd", "-ld", "aaa"
> and "'%s\n'" in succession. Clear the line (Ctrl-u).
> 
> Alt-. also correctly gives "sys", "..", "ccc" and "bar". (Ctrl-u to clear)
> 
> Now try the same thing with each of the other keystrokes, clearing the line
> between each test.
> 
> Alt-i: Instead of "getent", "ls", "echo" and "printf" you will see "getent",
> "getent", "ls" and "getent". Subsequent repetitions will alternate between
> "ls" and "getent".

This is a bug.  A zero count shouldn't change the direction (see below).
This will be fixed in the next version.

> Alt-j: Instead of "root", ".", "bbb" and "foo" you will see "root",
> "root", "." and "root". Subsequent repetitions will alternate between
> "." and "root".
> 
> Alt-k: Same behavior as Alt-j.
> 
> Alt-m: Instead of "passwd", "-ld", "aaa" and "'%s\n'" you will see "passwd",
> "passwd", "-ld" and "passwd". Subsequent repetitions will alternate between
> "-ld" and "passwd".
> 
> Other negative arguments behave similarly.

Yes.  In this case, the documentation is less than clear.  The count
argument is actually set by the first call to yank-last-arg, and that
argument sets the word to extract from the history entry.  Subsequent
calls to yank-last-arg without a different intervening editing command
use that same count as the argument to extract while moving through the
history, and any count given to those subsequent calls sets the number
of history entries to move.  A negative count on those calls changes the
direction.

You can get the behavior you want by using M-. (without an argument) on
the second and later successive calls to yank-last-arg.

Clearly the documentation needs updating.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]