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 6051 invoked from network); 7 Jul 2022 11:00:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Jul 2022 11:00:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1657191622; b=kWI29Ew4LSLDSK1RMJNswtzjXrtpVgKIm/TXEADNlvaR5gyj3/YKkWF6eKc8dcCopjb9a8Q+6S 5B2VoDZlkU52zLMovfhoFDiRAbvpAUXE84C9E4s2xY4unpNtwAsWlHALn40JI3BATUrgOJ/cAv 2hzFnDPQ41Y6jaFxD/RCGj8oImyScdDTT+3nvPQo+bVNs67r25ekWmluWKJ/swq94qEnsWEBip YoJSSmEa8hsxZSrf+uo6EJw+gXznHxswKvrxbA0KtGsRtAv+r3CwXCmKRaLUncsILdtI9jCUnY 6hNffCc8s6xWEO9PqcnUSy2dktCSemdmQ7FNCAFJgNGq2A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qt1-f177.google.com) smtp.remote-ip=209.85.160.177; 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=1657191622; bh=Vg5Nw9PR0Dh6fmSUB8CluhjJ6EFmqWUYCbNarV3K2Wc=; 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=mbk0tkRJZLOjfj6btI+N+p6aFYycDzcS8ijtd6r8MrEy5Kue1Mve1CBEaQ0ir3KCJWKdzcH5jx CmXcItQkwLm1y1QHf0J0Zeg5pnN4c/XRFAPVrvZ1o2sMW0gEYtDce0Pqfouwbr84WZKcO0xTew UtokAl5i7M0SoIVyZoT3UP2fNI83jxcF8ZldvGVvC9pnNjQEHXWy4nQ5Sy44AErKhHuqBtAa2L H4zMyq1fivm/NhSCT3m2jMIoMT2qJBkBmhPU/Cei/5U0DnI97ua5Pi6w3l5fBVCTsoHraB29X3 M05noezgpsxhjWHDBGBf7ha1Kqj+8G24/7WU8zi38VhP9A==; 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=9FnP/HJWjk54oSlu0kMmf7QUSRjNVCb+pXrwHIct8Gk=; b=OehQFafdECwcHwhQrfaP9s7QC0 sTV6WJSkqQymnRYTTigJmxo/4ytYGXRQ9PQhC+fl8y1EkuBe7Tajr9OmV4ygtOtGptFhxAXQWzOlT lU3OFaXcj1MR0vsDyOFqFBOpTJq1Khig55ZLAfn5Lr4VXiWINzPX7eKnIgHtrJFxQOI8PaW4J7rgc vZyWGDDmFuUk8U8yPNODmVX/VMH+Ecx92Ba5Xu1SV8yiiewKgj+fgE2BZCCZ7Xq9Yauy3u6HG6g6q skAderj2TOpr9MkSKbmuNWSO51aI0g8CDQK8nTf2ivg0mZXUiY/hBfe8qqhXd1aDmsIVXh7vlT48W PyGzzpHQ==; Received: from authenticated user by zero.zsh.org with local id 1o9PF6-000GsJ-RS; Thu, 07 Jul 2022 11:00:20 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qt1-f177.google.com) smtp.remote-ip=209.85.160.177; 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-f177.google.com ([209.85.160.177]:43571) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o9PEK-000G91-Mm; Thu, 07 Jul 2022 10:59:34 +0000 Received: by mail-qt1-f177.google.com with SMTP id c13so22084090qtq.10 for ; Thu, 07 Jul 2022 03:59:32 -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=9FnP/HJWjk54oSlu0kMmf7QUSRjNVCb+pXrwHIct8Gk=; b=IIqRqnOCNCqbDCZdSxOTdlQlIIMGDNV0DvFFfZFFz2CxTYGRBLNJx2pN/XZMXt7MQt SXDOHgoyA7upwmTPWVRsvKkzXH9wnhpKYr2JIPgzDyPBSLXCxiJ2HxjtMkfX96UeDwHN g97I3EGrqttAOkaLnTRERfChhdDzDVMzCDntbChsTI6MRsXq+9ySzy4OdQENy8QqtqG6 p4O7hN9XjNXdDlHWQGJbrwJ6K8/NZxbpcwoWAcEOBOfzYa04+5RlECHyHhPj7LunYCml yP168xLA4o38QfIGGvIouo7Pnarqcv6lbQbDwTD2pCq5J5pQmITnrf8s5zZaZT8Iw5Or +rUw== 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=9FnP/HJWjk54oSlu0kMmf7QUSRjNVCb+pXrwHIct8Gk=; b=W1i2165MBG2DmsJkC9syCGWuhsNDfm+MQ/KmP2xGXSLcuA9wAMW0o1WqthTORZNUze hH8IUV3FIIuAkyUrOdKY0dui76IRSDCAqetMLW0o6PwanjEHEdqLZvtHr1VcL9PIsIRg diQb0TfG3RjlgoP+NRDPenk5avNzMWESEGFkx3yLR67Dyy1etvQVWskLt77lmheDa218 8St1ECZED3uS6E+IGlvxmkWb2m5h9gGn2JY6OI/gFicoqGWQJOSzbB7jr3021vm9AvFq rO5TaxmZclxlbZ66glBbtuNSRCgdGZHEX9U5VN/20J6ecFtbpRZujbJqBeNhbmPeVaeP 4JOQ== X-Gm-Message-State: AJIora8ANAcBSLQkyfFkSSWXdq77iCOnLMKNUYvVP97cl0fIkKcQp6/b r9uT8l4I5U+3VfmsnBAGYT9VU24GWaCRwJLIadNII0VABAt3QA== X-Google-Smtp-Source: AGRyM1sx7l7HjADZA09yP36W1NULxUlVN+1rms6Wz/B2+hAM0a0q2mnLC9GOKb860UFcxpptLEH9mWz/cnUoe4Qtv90= X-Received: by 2002:a05:6214:27cc:b0:470:9aaa:94b5 with SMTP id ge12-20020a05621427cc00b004709aaa94b5mr39675144qvb.129.1657191571313; Thu, 07 Jul 2022 03:59:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ahmad Ismail Date: Thu, 7 Jul 2022 16:59:20 +0600 Message-ID: Subject: Re: How to parse zsh history To: Zsh Users Content-Type: multipart/alternative; boundary="000000000000eed65405e334fa75" X-Seq: 27872 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: --000000000000eed65405e334fa75 Content-Type: text/plain; charset="UTF-8" My current solution is: .... skim-history() { origquery=${BUFFER} # output=$(history 1 -1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact) # output=$(fc -ln 1 -1 | sk --tac --no-sort --exact) num=$(fc -l 1 -1 | sk --tac --no-sort --exact | rg -o '^[ ]*([0-9]*)[ ]*' -r '$1') if [ -n "$num" ]; then BUFFER=$(fc -ln $num $num) else BUFFER=$origquery fi # CURSOR=$#BUFFER # zle redisplay } zle -N skim-history bindkey '^R' skim-history .... Please let me know how can i make it better. On Thu, Jul 7, 2022 at 12:40 PM Ahmad Ismail wrote: > 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? >> >> >> >> >> >> --000000000000eed65405e334fa75 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
My current solution is:
....
skim-hist= ory() {
=C2=A0 origquery=3D${BUFFER}
=C2=A0 # output=3D$(history 1 -1= | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact)=C2=A0 # output=3D$(fc -ln 1 -1 | sk --tac --no-sort --exact)
=C2=A0 nu= m=3D$(fc -l 1 -1 | sk --tac --no-sort --exact | rg -o '^[ ]*([0-9]*)[ ]= *' -r '$1')

=C2=A0if [ -n "$num" ]; then
= =C2=A0 =C2=A0 BUFFER=3D$(fc -ln $num $num)
=C2=A0 else
=C2=A0 =C2=A0 = BUFFER=3D$origquery
=C2=A0 fi

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

zle =C2=A0 =C2=A0 -N =C2=A0 ski= m-history
bindkey '^R' skim-history
....

=
Please let me know how can i make it better.

On Thu, Jul 7, 2022 = at 12:40 PM Ahmad Ismail <ismail7= 83@gmail.com> wrote:
The way fzf do it is

=
....
fzf-history-widget() {
=C2=A0 local selected n= um
=C2=A0 setopt localoptions noglobsubst noposixbuiltins pipefail no_al= iases 2> /dev/null
=C2=A0 selected=3D( $(fc -rl 1 | perl -ne 'pri= nt if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
=C2=A0 =C2=A0 FZF_DE= FAULT_OPTS=3D"--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..= ,.. --tiebreak=3Dindex --bind=3Dctrl-r:toggle-sort,ctrl-z:ignore $FZF_CTRL_= R_OPTS --query=3D${(qqq)LBUFFER} +m" $(__fzfcmd)) )
=C2=A0 local re= t=3D$?
=C2=A0 if [ -n "$selected" ]; then
=C2=A0 =C2=A0 num= =3D$selected[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 f= i
=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
bindk= ey -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 <ismail783@gmail.com> wro= te:
My history file looks like:

....
: 165684= 6180:0;mint-vm
: 1657092275:4;g d fpull
: 1657092331:0;stow-dotfiles<= br>: 1657092447:0;fd --hidden --ignore-file .gitignore --base-directory=3D&= quot;$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookmarks" --type l -= -type f | sd ^. $HOME | xargs -I{} rm {}\

: 1657092530:0;fd --hidden= --base-directory=3D"$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookm= arks" --type l --type f | sd ^. $HOME | xargs -I{} rm {}\
stow --ta= rget=3D"$HOME" --dir=3D"$HOME/.dotfiles" --no-folding -= -restow .common-dotfiles-buggy-nemo-bookmarks\

: 1657092737:0;for i = in "${array[@]}"\
do\
=C2=A0\
=C2=A0DOWNLOAD_URL=3D$(cur= l -Lfs ${i} | grep -m1 -Po '(?<=3Dhref=3D")[^"]*zip')\=
=C2=A0FILE_NAME=3D$(echo $DOWNLOAD_URL | grep -Eo "([^\/]+$)"= )\
=C2=A0\
=C2=A0wget $DOWNLOAD_URL\
=C2=A0\
\
done
: 165= 7092752:15;array=3D( https://cinnamon-spices.linuxmint.com/appl= ets/view/83\
=C2=A0https://cinnamon-spices.linuxmint.co= m/applets/view/106\
=C2=A0https://cinnamon-spices.linux= mint.com/applets/view/222\
=C2=A0https://cinnamon-spice= s.linuxmint.com/applets/view/238\
=C2=A0https://cinnamo= n-spices.linuxmint.com/applets/view/284\
https://cinnamon-= spices.linuxmint.com/applets/view/303 )\
\
for i in "${array= [@]}"\
do\
=C2=A0\
=C2=A0DOWNLOAD_URL=3D$(curl -Lfs ${i} | gr= ep -m1 -Po '(?<=3Dhref=3D")[^"]*zip')\
=C2=A0FILE_N= AME=3D$(echo $DOWNLOAD_URL | 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 output=3D$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' = '' | sk --tac --no-sort --exact)

=C2=A0 if [ $? -eq 0 ]; the= n
=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 skim-history
bindkey '^R' skim-history
....

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

What= I found is, the only way zsh history=C2=A0parsing works correctly is if I = use something like !NUM, to get the history. How can I edit my zle extensio= n to do that?

Another option is (if previous fails= ), do not save multi line commands in history. How can I do that?





--000000000000eed65405e334fa75--