[Top][All Lists]

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

Re: edit-and-execute-command is appropriately named, weird

From: Chet Ramey
Subject: Re: edit-and-execute-command is appropriately named, weird
Date: Thu, 26 May 2011 12:09:32 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv: Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10

On 5/23/11 1:05 PM, David Thomas wrote:
> Hi all,
> In using bash over the years, I've been quite happy to be able to hit
> ctrl-x ctrl-e to pull up an editor when my input has grown too
> complicated.
> When using read -e for input, however, the behavior I find makes a lot
> less sense: the input line is still opened in an editor, but the
> result is not processed by read - it is executed by bash.  While a
> means to escape to the shell can certainly be useful it seems like it
> should generally be done in a more controlled environment.  It is much
> harder to reason about my scripts when arbitrary variables might be
> overwritten just because I asked for input.  In any case I'm not sure
> it makes sense to conflate this with the "open this line in an editor"
> command.

That editing command exists because Posix standardizes it for vi editing
mode. (Posix declined to standardize emacs editing mode at all.)  It was
useful to expose the same behavior when in emacs mode.

If you want an `edit-in-editor' command that just replaces the readline
editing buffer with the edited result, you should be able to write a shell
function to do that and use `bind -x' to make it available on any key
sequence you want (modulo the current restrictions on bind -x, of course).

Something like this:

        typeset p
        local TMPF=/tmp/readline-buffer

        rm -f $TMPF
        printf "%s\n" "$READLINE_LINE" > "$TMPF"
        ${VISUAL:-${EDITOR:-emacs}} $TMPF && READLINE_LINE=$(< $TMPF)
        rm -f $TMPF
        READLINE_POINT=0        # or p or ${#READLINE_LINE} or ...

Salt to taste.

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

reply via email to

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