zsh-users
 help / color / mirror / code / Atom feed
From: Ahmad Ismail <ismail783@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: How to parse zsh history
Date: Thu, 7 Jul 2022 11:56:30 +0600	[thread overview]
Message-ID: <CAHAhJwK9F30y8D47z-ZbE5F02xsxuOUhzG6HkGWgytXjKd+ZSQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2129 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 3173 bytes --]

             reply	other threads:[~2022-07-07  5:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  5:56 Ahmad Ismail [this message]
2022-07-07  6:40 ` Ahmad Ismail
2022-07-07 10:59   ` Ahmad Ismail
     [not found] ` <1728479877.503410.1657201438041@mail.virginmedia.com>
2022-07-07 13:46   ` Peter Stephenson
2022-07-07 18:16     ` Bart Schaefer
2022-07-18 12:48       ` Ahmad Ismail

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHAhJwK9F30y8D47z-ZbE5F02xsxuOUhzG6HkGWgytXjKd+ZSQ@mail.gmail.com \
    --to=ismail783@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).