zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Hendrik Jaeger <ml_zsh-workers@henk.geekmail.org>
Cc: zsh-workers@zsh.org
Subject: Re: Feature Request: completion for history events
Date: Mon, 16 Jan 2023 18:34:13 -0800	[thread overview]
Message-ID: <CAH+w=7bLooMGUFbgKt4Voyu3cPk3sRD+sk2DoYXz8xuvA-V94w@mail.gmail.com> (raw)
In-Reply-To: <20221229133959.27ce81c6@frustcomp.hnjs.home.arpa>

On Thu, Dec 29, 2022 at 4:41 AM Hendrik Jaeger
<ml_zsh-workers@henk.geekmail.org> wrote:
>
> I want to request a feature: completion for history events.

The usual ways to do this aren't exactly what you're envisioning.

The first way is, instead of starting out by typing "!", simply type
ESC-/ (the default binding for the _history_complete_word widget).

Another way is to add _history to your completer zstyle so that
history words are included when you type TAB.  Again you would not
start with "!", instead you'd type a few letters of the word you want,
or just hit TAB and find the word in the resulting list.  E.g.:
  zstyle ':completion:*' completer _oldlist _expand _complete _history
_approximate

Both of these are going to help you find the word you want and insert
the word directly, rather than completing a history event designator.
If you actually want to see a list of history events, we can build
something more complicated by stealing a bit of the guts of the _fc
completion function:

# --8< --
_complete_history_event () {
  local -a events expl
  local num cmd
  if [[ $words[CURRENT] = '!'(|-) ]]
  then
    for num cmd in "${(kv@)history}"
    do
      (( num=num - HISTNO ))
      events+=("${(r.1+$#HISTNO.)num} -- $cmd")
    done
    events=(${events/-/!-})
    _wanted -2V events expl "history event" compadd -Q -ld events -
"${events[@]%% *}" &&
      compstate[list]="list force"
  else
    return 1
  fi
}
_mainly_complete_history() {
  _main_complete _complete_history_event || _main_complete
}
zle -C complete-word .complete-word _mainly_complete_history
bindkey '\t' complete-word
# -->8 --

There's probably a better way to do that, the above is a quick hack
devised by looking at the _complete_debug output for "fc -".


  reply	other threads:[~2023-01-17  2:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-29 12:39 Hendrik Jaeger
2023-01-17  2:34 ` Bart Schaefer [this message]
2023-01-17  2:36   ` Bart Schaefer

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='CAH+w=7bLooMGUFbgKt4Voyu3cPk3sRD+sk2DoYXz8xuvA-V94w@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=ml_zsh-workers@henk.geekmail.org \
    --cc=zsh-workers@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).