zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: OG Code Poet <ogcodepoet@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Prompt user for single file with bells and whistles
Date: Sat, 11 Feb 2023 10:19:03 +0100	[thread overview]
Message-ID: <CAN=4vMoOn+FVZpznD1tUW7bJPwpoM=+5uTmykwN7a8kJk70LzQ@mail.gmail.com> (raw)
In-Reply-To: <CADmFDtXevwBrRd2jhp9QBxZsm3JkrsAjBoD-w1vNQsxk9_wG+w@mail.gmail.com>

On Fri, Feb 10, 2023 at 10:37 PM OG Code Poet <ogcodepoet@gmail.com> wrote:
>
> 1. Highlight: current menu selection item should be highlighted with reverse-video.
> 2. Order: the possible file completions should be shown below the prompt.
> 3. Prompt stepping: Prompt shouldn't step below after printing possible options above. This is related to 2.
> 4. Only one: Tab complete only first item, as we are asking for only 1 file name from user, not multiple. (This is what I mean by "functionally correct")
> 5. Size: If there are more possible completions than can fit below the prompt, that case is handled elegantly. Assume alternate screen, and no screen movement or scrolling available.
> 6. Bonus: If you could think of yet another nice feature to have for a single file selector, feel free to add. Though it would be nice to have it in a separate listing or with comments to identify how to remove your that from solution for 1-5 above.
>
> Note: The answer would be self-contained zsh code. It wouldn't ask user to edit .zshrc or install some zsh extension/plugin/framework/library.

How about this?

    #!/usr/bin/env -S zsh -fi

    zstyle ':completion:*' completer _files
    zstyle ':completion:*' menu yes select
    autoload -Uz compinit
    compinit
    vared -p "Select file: " -c file
    print -r -- "You selected: ${(q-)file}"

Roman.


      reply	other threads:[~2023-02-11  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10 21:36 OG Code Poet
2023-02-11  9:19 ` Roman Perepelitsa [this message]

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='CAN=4vMoOn+FVZpznD1tUW7bJPwpoM=+5uTmykwN7a8kJk70LzQ@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=ogcodepoet@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).