zsh-users
 help / color / mirror / code / Atom feed
From: OG Code Poet <ogcodepoet@gmail.com>
To: zsh-users@zsh.org
Subject: Prompt user for single file with bells and whistles
Date: Fri, 10 Feb 2023 13:36:14 -0800	[thread overview]
Message-ID: <CADmFDtXevwBrRd2jhp9QBxZsm3JkrsAjBoD-w1vNQsxk9_wG+w@mail.gmail.com> (raw)

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

After observing how menu selection looks for zim (
https://github.com/zimfw/zimfw), I decided to code a zsh prompt for user to
provide a single file and have some desirable features. The question was
recently posted on unix stackexchange. Here's the link:
https://unix.stackexchange.com/q/735012/456507 which has code listing and
GIFs. My first attempt at a single file prompt has multiple deficiencies at
the moment for which I would like to overcome. My understanding is that
these deficiencies require just a tiny list of options to turn on in zle,
though I cannot find it...

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.

Here's the copy of my seed code that needs more watering and nutrients:
Create a file ``foofiles.zsh`` in a temp directory, chmod and run it:
```zsh
#!/usr/bin/env zsh
setopt extendedglob
setopt globcomplete
setopt nomenucomplete

mkdir ./foo 2>/dev/null
cd ./foo
touch abcd ebcf gbch ijkl mnop qrst unov wxyz
cd ..

function foofileselector {
    cd ./foo/
    local curcontext=foofileselector:::
    vared -p "Select file: " -c foofile;
    cd ..
}

function _foofileselector {
    _files -W ./foo/
}

zstyle ':completion:foofileselector:*:' insert-tab false completer
_foofileselector

autoload -Uz compinit && compinit

foofileselector
[[ -z $foofile ]] && foofile="NIL"
echo "You selected: $foofile"

rm -rf ./foo/
```

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

             reply	other threads:[~2023-02-10 21:37 UTC|newest]

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

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=CADmFDtXevwBrRd2jhp9QBxZsm3JkrsAjBoD-w1vNQsxk9_wG+w@mail.gmail.com \
    --to=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).