Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Tip of the day: restoring an aborted command-line
- X-seq: zsh-users 20297
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Tip of the day: restoring an aborted command-line
- Date: Thu, 02 Jul 2015 00:12:59 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1435788782; bh=Yun/Kxw9qwnhgmcmMheF2zV/sJhJl46bA3g95cPfTiY=; h=From:To:Subject:Date:From:Subject; b=NZkhryo99Lsl2eCvKJgb+pXIgBkCkYBOjcWiXgYXWxLVMxdwNrWVCCAg/GhGj3Fma7epYGg3jlvN4Haq9hN7zVPLzZlrEM5YOTKNQ/YJEHOBiPrLp/dztuT3QcpPb6MuoTGQBASfdzjcLi0ugFwSAwAfaVm2bYOeHW7If7C6Zg9GXK1F0FlfbrV9IFL9omjzeWBjMKBTSBuvkaOyiPDpw2imE5vOkzhKp5p6htK4YgpjwqCyQ3emY4FigzKbtkR9dAE/lC/XB9HiNORLE8c7kwJE3cG0GTHz88DLFWcfDXWFTauI8P0bu7n5q8PplDe2sf6/Hi4y8dFGFFUv9I9Gig==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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 trick
instead creates an undo event so that you can simply use an undo to get
back the aborted line:
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
}
zle -N zle-line-init
Undo is bound by default to ^_, ^X^U and ^Xu in emacs mode and u in vi
command mode but I find it useful to bind it in vi-insert mode.
Also note the push-input widget if you want to put the current command
line aside but later restore it.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author