From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9568 invoked from network); 10 Feb 2023 21:37:18 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Feb 2023 21:37:18 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1676065038; b=aR5mxOn4HFi/xXABYWHnq+74+ZF2d4F4e1oNAMIiX5YuVXdcNsWERP5yMzN6Yp3QP7r0YmwXgS 3egwqxnP0AnL6+OzcxPnqPkModY1BFsJzNKTVBDdhjYLoCIGjhji3WSCwAz55kthfMW2NbNVKA LGxe7B7tYNs70uZI7RA3f3ZFbkgPNQC7R2A/Dk/byBzKFS7m0z9Ux827iO9zSaTm7rtLpnmVrW xfbdhUzxchm2XwE9JTEm+yIgZuQjY/AtTJ9OSXIone8+KW+1baAVHOgiTFPstoCK45Llq2Bcu3 Kzx0cL65tS60uXwa5htN6TiqZ08+i6Z4TcVHYAIFSa+3fg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ua1-f41.google.com) smtp.remote-ip=209.85.222.41; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1676065038; bh=iYl3bxFn8bmrC7Zqa5cSnzOO5QqXd71UAhjkeXDfWnw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=IB09OeN1AlyDl76p2oh6OTevQUyd+4zy7cfTi8YBbKmBEvTqvVMxobZrYNyFj8uuaDMTaytW1s JrS7k1Jmt6D5IUq+cIqHcp7Mr5YPpeAyBwNy/gUhC36Fkin0dfnKe/M14+T/Z35nFNN4nK0iyG PP1YFhGDlYt7EWIc0stFTfMvwXribh/uya/Vq8QUKmBfMRBXCaq/GayfZ2PlrsECQy9kIQkfsk yzrVigHc87O1c5dpidYfhdRBJYFjk/cuFpEfqXaN29YmqMtQ9eJco1/UrLo0g9HAr5+g5pS1Jk 5YEAJtmpDjSC6/DAMVVNQ1ca0njiiHhzbxhN/RCqJ7Y1iw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=pxja4Hl0o6QKgu/wl8SxxXivlEwnbBWIPNSgGP9EWNc=; b=QTvfE9dEDCY1UXE1jAU2dKpX4Y qfQiPi8nyxOHvwZvvtq74iRa3gMta8llavXt7DY06z/AkmqZHH2AHGTEIHV5sZa/FsTB50TJh/ihz M/G3SE0vUV43GkVHZye9P0l4SaMAFNJIBD7QYsEZBZhuTQRgE0wkKFO9QSNnhoptFGg52z+0KqQD6 HPse5SlS3tPXWzEgFfKCfm8CJ7fxlPJZ9qYv1SCxYuVNUdvT4nJsu6VrSEzs19mwLErqMtB/OP0cM u/Enxx+Vpe/AcFtCDh98lj0JrrOYmvK2MLGhYfI6rMyZvI/OtvO4Z+stfZM+W0ETFAYuk+38b+JPO 72d9FUbw==; Received: by zero.zsh.org with local id 1pQb53-000OI9-5s; Fri, 10 Feb 2023 21:37:17 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ua1-f41.google.com) smtp.remote-ip=209.85.222.41; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ua1-f41.google.com ([209.85.222.41]:38564) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pQb4E-000Nae-Nl; Fri, 10 Feb 2023 21:36:27 +0000 Received: by mail-ua1-f41.google.com with SMTP id v5so766495uat.5 for ; Fri, 10 Feb 2023 13:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=pxja4Hl0o6QKgu/wl8SxxXivlEwnbBWIPNSgGP9EWNc=; b=eG085x6cBMeKW5SDcHFqSBv9bxd2iQZ1k/vvwjH7F7Gyc8OTyx9n+Thja+whgl466J O1+bg3thI8i6cWVHpg5CHwcfmnuDmTUeySaL0Lg7KgGoBTt+iW/1bDjOa01LOBFHrsrB fCmAIxbeHVpVCcxRAcEiFQLLDlIjcrKDqw7CU/nBqI/UWesmuPVrTw40Bix0h72EQB99 esrKF/0Z4/p5GYacsulPoh0zM0W7IA92ZvILBYYqpnXAKmcQX2tpk7ZtXouW5vESiHBK Lesy1AjP7G0WXn8KfASSLZ1FUUes2dV6EDh5MM2aE23BQq1IAAoq0/TeP3QgUsOlyQ4C NU5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pxja4Hl0o6QKgu/wl8SxxXivlEwnbBWIPNSgGP9EWNc=; b=HKxPsCANBwLz+UTL6riSxDW10IAAmVcfnJCmyhJ0gJyN9klYT6rXCMm5kTdP2QX4/J /A7ApsTTjj0jRM65vOqeHKIlKDB3vMogA1xYcem4hnI96mDnPMpRgre3QTxbSAGPHQlp tonDIAzeWKOVPvfI3WaH8XnYvibCgaXRFs7ViiAT43YETzUkit5h+3dpNEfVdSxoZBU5 UkIeopyJM/yoV6Z9Opq7UIaBjLIBhVcfbajEmVTLNLowmO9ihti2N40S4eJ4oUv63pVV CxIkfXhRqUuGJ90m0ONeNnUFH/yRzy2IEhzabR8bfeY74DY3ndgJtWVRhTDlCilsPRH/ TzfA== X-Gm-Message-State: AO0yUKWKM7XIFpDW4kP5IxkZ7Ht4lecG3qIC8XTfBcKr/J8odewUQzyV UFebr9/kVNrhpEfv2ps5Io3QZd9OObybpdz4pIMm6RCWqBjPow== X-Google-Smtp-Source: AK7set++RKsh2gO4ADgjQQ3+C5NTZ3NV6XccqvhAYuaV5K1X7PiTFN0SG8fKTD6/MixzCJynDRsPFpd4LVYoiO6EJH0= X-Received: by 2002:ab0:30cd:0:b0:687:7cfa:80f with SMTP id c13-20020ab030cd000000b006877cfa080fmr1557739uam.47.1676064984928; Fri, 10 Feb 2023 13:36:24 -0800 (PST) MIME-Version: 1.0 From: OG Code Poet Date: Fri, 10 Feb 2023 13:36:14 -0800 Message-ID: Subject: Prompt user for single file with bells and whistles To: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="0000000000000c168b05f45f4a52" X-Seq: 28910 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --0000000000000c168b05f45f4a52 Content-Type: text/plain; charset="UTF-8" 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/ ``` --0000000000000c168b05f45f4a52 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 stackexc= hange. Here's the link: https://unix.stackexchange.com/q/735012/456507 which has co= de listing and GIFs. My first attempt at a single file prompt has multiple = deficiencies at the moment for which I would=C2=A0like to overcome. My unde= rstanding is that these deficiencies=C2=A0require just a tiny list of optio= ns to turn on in zle, though I cannot find it...

1. Highlight: current menu selection item should be highlighted with rev= erse-video.
2. Order: the possible file completions should be shown belo= w 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 prom= pt, that case is handled elegantly. Assume alternate screen, and no screen = movement or scrolling available.
6. Bonus: If you could think of yet ano= ther nice feature to have for a single file selector, feel free to add. Tho= ugh it would be nice to have it in a separate listing or with comments to i= dentify how to remove your that from solution for 1-5 above.

Note: T= he answer would be self-contained zsh code. It wouldn't ask user to edi= t .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 director= y, chmod and run it:
```zsh
#!/usr/bin/env zsh
setopt exten= dedglob
setopt globcomplete
setopt nomenucomplete

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

function foofileselector {
=C2=A0 =C2=A0 cd ./foo/
= =C2=A0 =C2=A0 local curcontext=3Dfoofileselector:::
=C2=A0 =C2=A0 vared = -p "Select file: " -c foofile;
=C2=A0 =C2=A0 cd ..
}
function _foofileselector {
=C2=A0 =C2=A0 _files -W ./foo/
}

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

autoload -Uz compinit && compinit

fo= ofileselector
[[ -z $foofile ]] && foofile=3D"NIL"
= echo "You selected: $foofile"

rm -rf ./foo/
= ```
--0000000000000c168b05f45f4a52--