zsh-users
 help / color / mirror / code / Atom feed
* Prompt user for single file with bells and whistles
@ 2023-02-10 21:36 OG Code Poet
  2023-02-11  9:19 ` Roman Perepelitsa
  0 siblings, 1 reply; 2+ messages in thread
From: OG Code Poet @ 2023-02-10 21:36 UTC (permalink / raw)
  To: zsh-users

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-11  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 21:36 Prompt user for single file with bells and whistles OG Code Poet
2023-02-11  9:19 ` Roman Perepelitsa

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).