From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6884 invoked from network); 7 Jul 2022 06:46:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Jul 2022 06:46:44 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1657176405; b=OsBEvuENC1leMzjQeYkYEJ8GsJuP16Ng3ag+roEugp2feNnDxy+cnKxs/qwSNbiB58vBWBRho1 wK3J3naAk0a6tCdt2lqCV+I+UZppZtejHC8ZUPCFt47harZBOck5Ixffn1+64cAcgVwDOs4OEp TtcedTst34rAqStz7IhYTNeBz8PUVme6ks6GXBiheyaXO9k7hxEjOcxWWH/TouXmHr3IDIUNR9 Ay0mGQcEJK9Ew09IaqYbUbduqgrQRm3vnoeeofOSpCepaqLLqUFFw+cBuVXj2Wfh36W6ipoS3E Nm5JK5KR3weMXMtWYZZrxvGYqnWXK1gtqtMGH/+sTvLxjQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qt1-f178.google.com) smtp.remote-ip=209.85.160.178; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1657176405; bh=kcR0Qh1t4R1md7148n5rVCQERqqDlpAL+5ZyRxT0NE8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=KhuMuiD3Yd+RCybTJyjxpmIRb3h98gTAlGGZM2GtEdgUHfnk3WJ/aGpeLoOnyCdXKbEpF5uYrY kNrCMjLeUgoGs1/I+aZSZIoy56Lq5Gl5RMCJeMHD6wW1yTJSUor0AicN3bvx+Ln1X/l3aECnQ1 6miGI0DA2cKUuRIgKbpLFYzkZHYSgfDCeJdij6SxrmGVEWGjzZWdUFk74cUN63EonmhjWRc4aU /IWhdZ4KZVJSXWASm9EIYM7Yh2eSyZLNg8Ds4+z/kwgJNb6AY8pzHh6uyxOCXMQD3b7qkkuft9 l5/fN6Is5s8+mt9CnD0mcPJdaMFn9mVfQMEtWOEZ63E8pg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=q2aNePDdIWMmQU5qF+2mH1PmP2RywqM7JGSBn/XVXzU=; b=fqsIAcTls9LZUmlm4jh5G1lVQZ BcFTuB6TINzqzuzESgpxRkLB7YkQbo5HNkDvpGYO1EB6RzrUv+bgi1dXEeptXHoi58M+1k286LRRp 6V2OlPdbS763OZXp8hjOAgt7z8cf4/DYjbGDqtuZHR9rudhd6hIbGMOg1hlO0bFNuBAhw+hKsNnsk xN+/TE4nCnFozPIDKiNj++uneBb0A2BMny1j27p2KwG76Wz/5IlGg5p9Zk0XGGwRR5/dYISOj3tm7 cv3OABukyaqQuUHoBknji/c9A28swpYXdM5pNdgWeDw8paM+pV4p3tjYyeY60ki17dyEzNe9aT4zy RX8oWlGA==; Received: from authenticated user by zero.zsh.org with local id 1o9LHg-0009OW-EY; Thu, 07 Jul 2022 06:46:44 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qt1-f178.google.com) smtp.remote-ip=209.85.160.178; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-qt1-f178.google.com ([209.85.160.178]:46856) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o9LCC-0008YW-Ln; Thu, 07 Jul 2022 06:41:05 +0000 Received: by mail-qt1-f178.google.com with SMTP id he28so21440365qtb.13 for ; Wed, 06 Jul 2022 23:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=q2aNePDdIWMmQU5qF+2mH1PmP2RywqM7JGSBn/XVXzU=; b=G0Sf91KisFcrW8vnltFD5Wwq13rYUHUPDDM3+afwpG6JRrw3rptfJCOdqZ7hpAH3JR zzieInqZjgtc7D9w0JusuJDngbQ7aZOla4eLSvOo61ekyxaXN+ZL1R66NjHdgIqEyOOI Im4Q35EmuF0TmH9rGTzRqsZ8oxmo890mVHKvG6z9FsOD/+/WZKFT8qnT6wpdic/oZQoq nmNNkA64oQ4KwEfS+sn+0pJjcVzVLoQ55P3dMvF+ZkbGJ+7viszOIxc+uUbT6Skz/LKg swCnQWIKRPF3v4wII7SBKOU94MFnKoPErODkKFFB2PZFlu8kfsPnyrQWLlGirhAOeYm9 NPwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=q2aNePDdIWMmQU5qF+2mH1PmP2RywqM7JGSBn/XVXzU=; b=pWrylkzVEMNd2k5D5iX+x2FpP4xiLCbK8v4WYn3uzu2xHHvKxT7cpbESrTLr0YCgl3 KiZ5pIrziw/D9VX12i09A1zXu4w6OEEr0lMEWE7YxmQBwqCN6ChJQJoqgMjsjc1C5ULg VG122hi/5aeG2nQflXS6EF039Brq4g8qc9VVPRIQzUGj4NyXOQSPp9UHWxvXw+MUpqFQ 1sl23P3qFDQ79gfGm/0rqpGPoobgfcbotx3pvql7QIqkujx6s9fOFKqeThe0VaaYMsks 0Ib6kd9CceAq0/MVCprZUDffjE0WdtMXQvk/orSkSkUczguKLfXkZnAjpwR8RMIqfvKA p/QQ== X-Gm-Message-State: AJIora89iuS5WYbLc01MSYB6x0ABUzV/M17AF8KcwvURmbNHezurDss7 c1a4aFZTU6knHyJ1K2BVmUPbedI4wC19nccGJOcCFwt/C0lN3w== X-Google-Smtp-Source: AGRyM1v42hfM64L61cNXYK570DN3Y0z8z6gVvJtQhSjjB5vn6x/Ls0owOtTtGKMUeiJyr4IFdE2ZkLpc0g5TiutGRY8= X-Received: by 2002:a05:6214:27cc:b0:470:9aaa:94b5 with SMTP id ge12-20020a05621427cc00b004709aaa94b5mr39004281qvb.129.1657176063213; Wed, 06 Jul 2022 23:41:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ahmad Ismail Date: Thu, 7 Jul 2022 12:40:52 +0600 Message-ID: Subject: Re: How to parse zsh history To: Zsh Users Content-Type: multipart/alternative; boundary="0000000000009407db05e3315e19" X-Seq: 27871 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --0000000000009407db05e3315e19 Content-Type: text/plain; charset="UTF-8" The way fzf do it is .... fzf-history-widget() { local selected num setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort,ctrl-z:ignore $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) ) local ret=$? if [ -n "$selected" ]; then num=$selected[1] if [ -n "$num" ]; then zle vi-fetch-history -n $num fi fi zle reset-prompt return $ret } zle -N fzf-history-widget bindkey -M emacs '^R' fzf-history-widget bindkey -M vicmd '^R' fzf-history-widget bindkey -M viins '^R' fzf-history-widget .... but I want to do it with skim instead of fzf. On Thu, Jul 7, 2022 at 11:56 AM Ahmad Ismail wrote: > My history file looks like: > > .... > : 1656846180:0;mint-vm > : 1657092275:4;g d fpull > : 1657092331:0;stow-dotfiles > : 1657092447:0;fd --hidden --ignore-file .gitignore > --base-directory="$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookmarks" > --type l --type f | sd ^. $HOME | xargs -I{} rm {}\ > > : 1657092530:0;fd --hidden > --base-directory="$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookmarks" > --type l --type f | sd ^. $HOME | xargs -I{} rm {}\ > stow --target="$HOME" --dir="$HOME/.dotfiles" --no-folding --restow > .common-dotfiles-buggy-nemo-bookmarks\ > > : 1657092737:0;for i in "${array[@]}"\ > do\ > \ > DOWNLOAD_URL=$(curl -Lfs ${i} | grep -m1 -Po '(?<=href=")[^"]*zip')\ > FILE_NAME=$(echo $DOWNLOAD_URL | grep -Eo "([^\/]+$)")\ > \ > wget $DOWNLOAD_URL\ > \ > \ > done > : 1657092752:15;array=( > https://cinnamon-spices.linuxmint.com/applets/view/83\ > https://cinnamon-spices.linuxmint.com/applets/view/106\ > https://cinnamon-spices.linuxmint.com/applets/view/222\ > https://cinnamon-spices.linuxmint.com/applets/view/238\ > https://cinnamon-spices.linuxmint.com/applets/view/284\ > https://cinnamon-spices.linuxmint.com/applets/view/303 )\ > \ > for i in "${array[@]}"\ > do\ > \ > DOWNLOAD_URL=$(curl -Lfs ${i} | grep -m1 -Po '(?<=href=")[^"]*zip')\ > FILE_NAME=$(echo $DOWNLOAD_URL | grep -Eo "([^\/]+$)")\ > \ > wget $DOWNLOAD_URL\ > \ > \ > done > .... > > I am working on a widget for fuzzy search history. > > .... > skim-history() { > origquery=${BUFFER} > output=$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort > --exact) > > if [ $? -eq 0 ]; then > BUFFER=$output > else > BUFFER=$origquery > fi > > CURSOR=$#BUFFER > } > > zle -N skim-history > bindkey '^R' skim-history > .... > > In `history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact`, > sd is used instead of sed, which just removes numbers from the beginning. > However, it messes things up if the command is multi-line. > > What I found is, the only way zsh history parsing works correctly is if I > use something like !NUM, to get the history. How can I edit my zle > extension to do that? > > Another option is (if previous fails), do not save multi line commands in > history. How can I do that? > > > > > > --0000000000009407db05e3315e19 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The way fzf do it is

.= ...
fzf-history-widget() {
=C2=A0 local selected num
=C2=A0= setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> = /dev/null
=C2=A0 selected=3D( $(fc -rl 1 | perl -ne 'print if !$seen= {(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
=C2=A0 =C2=A0 FZF_DEFAULT_OPTS= =3D"--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tieb= reak=3Dindex --bind=3Dctrl-r:toggle-sort,ctrl-z:ignore $FZF_CTRL_R_OPTS --q= uery=3D${(qqq)LBUFFER} +m" $(__fzfcmd)) )
=C2=A0 local ret=3D$?
= =C2=A0 if [ -n "$selected" ]; then
=C2=A0 =C2=A0 num=3D$select= ed[1]
=C2=A0 =C2=A0 if [ -n "$num" ]; then
=C2=A0 =C2=A0 = =C2=A0 zle vi-fetch-history -n $num
=C2=A0 =C2=A0 fi
=C2=A0 fi
=C2= =A0 zle reset-prompt
=C2=A0 return $ret
}
zle =C2=A0 =C2=A0 -N =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fzf-history-widget
bindkey -M emac= s '^R' fzf-history-widget
bindkey -M vicmd '^R' fzf-hist= ory-widget
bindkey -M viins '^R' fzf-history-widget
....

but I want to do it with skim instead of fzf.

On Thu, Jul 7, 2022 at 11:56 AM Ahmad Ismail <ismail783@gmail.com> wrote:
My history file looks l= ike:

....
: 1656846180:0;mint-vm
: 16570922= 75:4;g d fpull
: 1657092331:0;stow-dotfiles
: 1657092447:0;fd --hidde= n --ignore-file .gitignore --base-directory=3D"$HOME/.dotfiles/.common= -dotfiles-buggy-nemo-bookmarks" --type l --type f | sd ^. $HOME | xarg= s -I{} rm {}\

: 1657092530:0;fd --hidden --base-directory=3D"$H= OME/.dotfiles/.common-dotfiles-buggy-nemo-bookmarks" --type l --type f= | sd ^. $HOME | xargs -I{} rm {}\
stow --target=3D"$HOME" --d= ir=3D"$HOME/.dotfiles" --no-folding --restow .common-dotfiles-bug= gy-nemo-bookmarks\

: 1657092737:0;for i in "${array[@]}"\<= br>do\
=C2=A0\
=C2=A0DOWNLOAD_URL=3D$(curl -Lfs ${i} | grep -m1 -Po &= #39;(?<=3Dhref=3D")[^"]*zip')\
=C2=A0FILE_NAME=3D$(echo= $DOWNLOAD_URL | grep -Eo "([^\/]+$)")\
=C2=A0\
=C2=A0wget = $DOWNLOAD_URL\
=C2=A0\
\
done
: 1657092752:15;array=3D( https://cinnamon-spices.linuxmint.com/applets/view/83\
=C2=A0https://cinnamon-spices.linuxmint.com/applets/view/106\
= =C2=A0https://cinnamon-spices.linuxmint.com/applets/view/222\<= /a>
=C2=A0
https://cinnamon-spices.linuxmint.com/applets/vie= w/238\
=C2=A0https://cinnamon-spices.linuxmint.com/appl= ets/view/284\
https://cinnamon-spices.linuxmint.com/applet= s/view/303 )\
\
for i in "${array[@]}"\
do\
=C2= =A0\
=C2=A0DOWNLOAD_URL=3D$(curl -Lfs ${i} | grep -m1 -Po '(?<=3D= href=3D")[^"]*zip')\
=C2=A0FILE_NAME=3D$(echo $DOWNLOAD_UR= L | grep -Eo "([^\/]+$)")\
=C2=A0\
=C2=A0wget $DOWNLOAD_URL= \
=C2=A0\
\
done
....

I am = working on a widget for fuzzy search history.

....=
skim-history() {
=C2=A0 origquery=3D${BUFFER}
=C2=A0 outpu= t=3D$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --n= o-sort --exact)

=C2=A0 if [ $? -eq 0 ]; then
=C2=A0 =C2=A0 BUFFER= =3D$output
=C2=A0 else
=C2=A0 =C2=A0 BUFFER=3D$origquery
=C2=A0 fi=

=C2=A0 CURSOR=3D$#BUFFER
}

zle =C2=A0 =C2=A0 -N =C2=A0 sk= im-history
bindkey '^R' skim-history
....

In `history -1 1 | sd '^[ ]*[0-9]*[ ]*' ''= | sk --tac --no-sort --exact`, sd is used instead of sed, which=C2=A0just = removes numbers from the beginning. However, it messes things up if the com= mand is multi-line.

What I found is, the only way = zsh history=C2=A0parsing works correctly is if I use something like !NUM, t= o get the history. How can I edit my zle extension to do that?
Another option is (if previous fails), do not save multi line = commands in history. How can I do that?


=



--0000000000009407db05e3315e19--