From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27778 invoked by alias); 19 Apr 2014 03:27:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32567 Received: (qmail 26873 invoked from network); 19 Apr 2014 03:27:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140418202739.ZM24101@torch.brasslantern.com> Date: Fri, 18 Apr 2014 20:27:39 -0700 In-reply-to: Comments: In reply to Dave Yost "function to replace the command line text" (Apr 18, 12:49pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Dave Yost , zsh-workers@zsh.org Subject: Re: function to replace the command line text MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Apr 18, 12:49pm, Dave Yost wrote: } } Is there a builtin function that replaces the command line with the } function's output? As Frank demonstrated, the most basic "function" for this is to assign to the special parameter $BUFFER from inside a user-defined ZLE widget. However ... } I want to use that function to build a function I can use to run a } demo consisting of a sequence of commands. } * Make an array of strings } * For each step of the demo } * Type a command or a keyboard shortcut that grabs the next string } from the array and places it on the command line } * Hit Enter to execute the command There are a bunch of ways to do this. If you just want to execute the commands one after another, you could: - Store the commands in a file, one per line; - Load the file as history with "fc -R" or "fc -p"; - bindkey ^M accept-and-infer-next-history; - scroll back (up-history) to the first command; - each subseqent enter executes the command and advances to the next. This has the advantage that you can up-history to redo any command. If that isn't likely to be necessary you can: - push the commands onto the buffer stack, in reverse order, with one "print -z" per command; - press enter to load the first command; - each subseqent enter executes the command and pops the next. Here you'd have to use the push-line widget and then up-history if you want to redo a command. If you want to be able to go off-script to execute some other commands and then resume the demo, then you'll need something like what Frank outlined, with a key binding to produce the next step when ready. If you hit the "next step" key more than once, though, you'll skip over a command step and have no way to get back to it, unless you also create another binding that steps down through the array. Here's a variation of Frank's FOO widget that lets you select which step of the demo you want, and by default goes on to the next: FOO() { if (( NUMERIC > 0 )) then (( j=NUMERIC )) elif (( NUMERIC < 0 )) then (( NUMERIC > -j ? (j+=NUMERIC) : (j=1) )) fi BUFFER=${foo[j++]}; CURSOR=${#BUFFER} } You press ESC 2 ^L, for example, to select the second step, or to go backward, ESC - ESC 1 ^L (repeats the last step).