From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9916 invoked by alias); 2 Jul 2015 23:18:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20301 Received: (qmail 14701 invoked from network); 2 Jul 2015 23:18:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 Message-ID: <1435878673.17325.5.camel@niobium.home.fifi.org> Subject: Re: Tip of the day: restoring an aborted command-line From: Philippe Troin To: zzapper Cc: zsh-users@zsh.org Date: Thu, 02 Jul 2015 16:11:13 -0700 In-Reply-To: References: <30469.1435788779@thecus.kiddle.eu> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit On Thu, 2015-07-02 at 21:29 +0000, zzapper wrote: > Oliver Kiddle wrote in > news:30469.1435788779@thecus.kiddle.eu: > > > When you abort a command-line with Ctrl-C or whatever, the Zsh line > > editor sets $ZLE_LINE_ABORTED to the contents of the command-line > > before it was aborted. Sometimes you might want to recover the aborted > > line and you could bind a dedicated key to that purpose. The following > > > > > zle-line-init () { > > if [[ -n $ZLE_LINE_ABORTED ]]; then > > local savebuf="$BUFFER" savecur="$CURSOR" > > BUFFER="$ZLE_LINE_ABORTED" > > CURSOR="$#BUFFER" > > zle split-undo > > BUFFER="$savebuf" CURSOR="$savecur" > > fi > > } > > > Oliver > is $ZLE_LINE_ABORTED dependent on any autoload? as i have it on cygwin > but not on centos (both 5.08) It shouldn't. I'd like to propose the following enhancement: zle-line-init () { if [[ -n $ZLE_LINE_ABORTED ]]; then _last_aborted_line=$ZLE_LINE_ABORTED fi if [[ -n $_last_aborted_line ]] then local savebuf="$BUFFER" savecur="$CURSOR" BUFFER="$_last_aborted_line" CURSOR="$#BUFFER" zle split-undo BUFFER="$savebuf" CURSOR="$savecur" fi } zle -N zle-line-init zle-line-finish() { unset _last_aborted_line } zle -N zle-line-finish Now this handle the case when you press Ctrl-C multiple times in a row. Eg: zsh% foo=^C zsh% ^C zsh% ^C zsh% zsh% foo= Phil.