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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5248 invoked from network); 7 Apr 2021 18:15:38 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Apr 2021 18:15:38 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617819338; b=eM5RQuJz9GDfYtnM+/Fq47DX5vPym20uSS34KZGG/PuF+8A5D8h15g9b/tbfyI038Gdcr0k7cp VVYCMbkGcFoYasC6uuJ0oStSthxmHpM6DjfnagZDTk6VZmHuowdKb9DUdf7+EUq98bkhcG9YYr oApzGoFWnXKHtQuA5Q/F1Oz/nuH+mAfsjMNCt8N12JYbpxUhI3QhD7e7KKiPcI/QKki3EE9m+a IzIS65XYNaQwMZ74wCblF0g55LvYq+Jm/FyQIquZPzEZZmtYEWO8WHqNpmHQaOOigit7abOCqo F4XRKtJpcVx2tru9kWFxmjQ7FJ9hEeZtA/6nujYp43LJUQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-il1-f171.google.com) smtp.remote-ip=209.85.166.171; dkim=pass header.d=gmail.com header.s=20161025 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-20200801; t=1617819338; bh=4PtlXp09HgnL1iS8aKjzuj+v5uKJm1BZLyIDL9m9EmM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=YoB7LU10uITNZPT2HrcTcUBRRUW9RVEUmrRxkbrnsuV0eKqJGH6Rz2/PolxynaEICdmSFFuvYC oU+933Yai6JxRETqXVith2Hix4XI0FBiDuWVNuQz34vZC6gWyrVFXH5EzNhYQtmSzc3A9VnXjZ wiVZsAKEsYEDBLYJ8x9ZOZhFP07ritqXFYHvSlSEA9BGziy/SsevVTnhTTvnJi3zksKN+s1t7X ELDxLOuyvWyBHc0DimHTOjMnqK4G2QqqtSobDrbp7KocSnhgLQwD4ZbJqshO6fPp5MqT7a+NUR eQi99Fl7KbNGs/pXC0UFiLafleIzQ1J/s0h5jojCpbZE/A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=IwKO0zu/2cgO9GDvAlCOSk5GQNNerrwYXET7SqZuEiw=; b=A1oGVjQqc3Ot0Pc9fw3QpiDHY4 fzLU3h8dspT0usmErrB1KZ1GvGt/yY+2Fc0OzHpEhhCcEZbsQ+WETPGTE92DkH6M2c/5dV7ETJ2q0 CXe5VGC/h5hvvTXGyVplm6Zva0mcb/ItMq0SAQiqdVJycWEG9IkYAuEG27+aH3/qgKTT9lQErgQNi YbeJs/GdkS1TAcELVF8h/u8YsP+Y91Yp8Eaoz7MGTPIrN4m94VjjQ+kMoweePyOqjUTuCNNiA4fy7 3P9GWhmB/xVcKrzAQQfsWhDe7rgube5v2OfDWYt+a0+41J/4LecUtIgSHUNaVyKSNVi38AKwA4KkU xuGueU5A==; Received: from authenticated user by zero.zsh.org with local id 1lUCiF-0008hr-MI; Wed, 07 Apr 2021 18:15:35 +0000 Authentication-Results: zsh.org; iprev=pass (mail-il1-f171.google.com) smtp.remote-ip=209.85.166.171; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-il1-f171.google.com ([209.85.166.171]:44699) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lUCi0-0008SU-Nm; Wed, 07 Apr 2021 18:15:21 +0000 Received: by mail-il1-f171.google.com with SMTP id o15so12912679ilf.11 for ; Wed, 07 Apr 2021 11:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=IwKO0zu/2cgO9GDvAlCOSk5GQNNerrwYXET7SqZuEiw=; b=ZGDgKj93rghxTADL6IlEEdjygzvhvP6MewN/oeoNkGKe6rW9/OvtYxhqofisjyDmjj Dwfr7ss8upbAuHyyVrUhj1qPxBELI7i/JGd4MLLAeTqqHE5+F6vVlSG3nvRwTPWTvTXN 4xgpGi4Z4dh0dPODAUeI2E1zozjqf9H76TM/IZG6YP8hqmWXoCTOLF9ryZiKihBsugFI 1x3VWc5nZgNiP22kI4qQNbBOJyxYoOpMoUOw/Jjd074EBi5JrUoxxkmquW81kC//LRSg Loho469kqIBtiOhdzNKkAsX/EXxChCPWtRffE8vTLcsdXtKDjHiEP3J8tULe7LKqDf2x A//g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=IwKO0zu/2cgO9GDvAlCOSk5GQNNerrwYXET7SqZuEiw=; b=gFTxAmknmjcnN4CdRm0D9OWthO6Y55h8E+HmV+YCBxQr2vNfJhudVnWNW6NBmihPKY Ns5Naq+ODcVYxVpPOvys4hVLFunp0GixO/kyt1rEuNXfenxJ2cI9G2huU584AG1hbPFd XYbF0oZLKOKCOkeNSv068cHf0s4XXqrNScIPnFqpyVhXv7kkIb+1mZTByaBxmOBKkDK5 sAc0OCmTKYECXqel2Sh8HFzwj0wFzLqbYyydIQJCAX/OrfXwfRDLHG17CFDLVksoxPkS BMI5+bFj0MEq7VEoO4lHpuz4tQYdVuSHr8NPv/xSOi5wZixdOr6u9pvTe1QLBU/YYCW6 G1Pw== X-Gm-Message-State: AOAM532tjIqYmxJ5WfDZfYlSvP32OV0HTLagPbgCyZlwVbbcIihhRJES aUHxGdJI7gBe22zWVj4RGVTx13M3jdd09PR0YPI= X-Google-Smtp-Source: ABdhPJxqvz10p2D2LEW45sLgRsrCN12JqqKSwuhTIR0biMrS8LMJy+Igrs6dhPfEfSKwEVmZLDRIIooQx9crybf1pqE= X-Received: by 2002:a92:d0a:: with SMTP id 10mr3901224iln.25.1617819319649; Wed, 07 Apr 2021 11:15:19 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:d144:0:0:0:0:0 with HTTP; Wed, 7 Apr 2021 11:15:18 -0700 (PDT) In-Reply-To: References: From: Mikael Magnusson Date: Wed, 7 Apr 2021 20:15:18 +0200 Message-ID: Subject: Re: Rewrite of zsh-newuser-install (Mikael's subthread) To: Marlon Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 48427 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On 4/7/21, Marlon wrote: > >> On 5. Apr 2021, at 22.44, Mikael Magnusson wrote: >> >> On 4/5/21, Marlon Richert wrote: >>> # >>> # Type `zrestart` to safely apply changes after editing this file. >>> # >>> zrestart() { >>> local zshrc=3D${ZDOTDIR:-$HOME}/.zshrc >>> print -P "Validating %U$zshrc%u..." >>> zsh -nf $zshrc || >>> return >>> >>> print -P 'Restarting Zsh...' >>> zsh -l && >>> exit >>> } >> >> This could be an autoloadable function, not pasted verbatim in .zshrc. >> Also disagree with -l here. You can use $options[login] or $- to see >> if you're in a login shell already and start same. Things like this we >> can't fix after users already copy this config. It should try to >> mostly be configuration, not helper functions that can have permanent >> flaws once installed. > > Sure, I can move it to an autoloadable function. That=E2=80=99s fine by m= e. I did > not come up with the -l, though. Earlier in the thread, Oliver & Bart did= n=E2=80=99t > like using `exec zsh` and offered this instead. See > [48031](https://www.zsh.org/mla/workers/2021/msg00244.html). I=E2=80=99d = be happy to > change it, but I don=E2=80=99t know how they feel about it. You could also just have a comment saying something to the effect of "changes to this file will only take effect in new shells, you can either open a new terminal or type "zsh" in an existing terminal". I guess I don't care too much either way after all. >>> setopt EXTENDED_HISTORY # Save each command's time & duration t= o >>> history. >>> setopt INC_APPEND_HISTORY_TIME # Save history whenever a command >>> finishes, not just on shell exit. >>> setopt HIST_EXPIRE_DUPS_FIRST # Delete duplicate history lines first, >>> when running out of space. >>> setopt HIST_IGNORE_DUPS # Don't store last command line if >>> identical to previous one. >> >> ok, I don't agree with the dups settings but they're changeable easily. > > Personally, I would=E2=80=99ve preferred `setopt HIST_IGNORE_ALL_DUPS > SHARE_HISTORY`, but there were several votes against that earlier in this > thread. I'm glad, those are even worse :). >>> # Up/Down: Cycle through history lines that start with same word as >>> command line. >>> zle -A up-line-or-{search,history} >>> zle -A down-line-or-{search,history} >> >> These two lines don't actually bind any keys, but the comment claims the= y >> do. > > They change the default widgets bound to up/down, which makes for more > elegant code, since we don=E2=80=99t have to deal with app vs raw mode. Ah, I didn't realize that's what you did because the {,} stuff makes it way too hard to understand at a glance. What you're doing is in fact making it impossible (unless the new user knows about .widgets) for the user to bind up-line-or-search to any other key, without first hunting down and deleting these two lines. I don't like it... Overall I would say you should get rid of all brace expansions. [snipped delete] >>> # Tab/Shift-Tab: Start type-ahead completion. >>> # * Tab: Insert substring shown by `interactive: >>> []`. >>> # * Shift-Tab: Accept selection & start next completion. >> >> Would never expect shift-tab to do anything else than reverse order >> completion. > > I would expect Tab to insert the current selection, not insert an > =E2=80=9Cunambiguous=E2=80=9D prefix or _just do nothing_ when such a pre= fix doesn=E2=80=99t exist. > However, I don=E2=80=99t want to override the defaults when I can avoid i= t. So, > that=E2=80=99s why I added Backtab to do what, since that actually doesn= =E2=80=99t have any > function by default; not in the ZLE and not in complist=E2=80=99s `intera= ctive` > mode. > > Also, in complist=E2=80=99s `interactive` mode, Tab does _not_ cycle forw= ard, but > inserts =E2=80=9Cunambiguous". Ergo, in this context, I would _not_ expec= t to > Backtab to cycle backwards. tab will insert the unambiguous part, and then start cycling (depending on your setopts, this takes anywhere from 0 to 4 or so tab presses). >>> # * Arrow keys: Change selection. >>> # * Enter: Accept selection & stop completing. >>> zstyle ':completion:(|reverse-)menu-complete:*:default' menu yes select >>> interactive >> >> I don't agree with enabling menu selection by default, but maybe just >> because I hate menu selection... It should at any rate be made clearer >> how to disable it (in all places). > > `interactive` means it=E2=80=99s not actual menu selection, though. Inste= ad, it > enables type-ahead completion, which is an extremely useful complist > feature. Well, I'd have the same objection to either of them, that it's quite a huge departure from the standard mode of operation which is typing normally and pressing tab to complete words. >>> bindkey "$key[Tab]" menu-complete >>> zle -C {,.}menu-complete _generic >>> bindkey "$key[Backtab]" reverse-menu-complete >>> zle -C {,.}reverse-menu-complete _generic >> >> I don't think that a "newbie friendly .zshrc" is the place to start >> changing the default handler of completion widgets. Also all of these >> {,.} everywhere should probably have some explanatory comment, it's >> not obvious what those lines are even for (I know, of course, but I >> had to think about it... So probably not obvious to a newbie). > > Sadly, without using _generic, it=E2=80=99s not possible to enable or dis= able menu > selection on an individual widget basis. That=E2=80=99s why I filed > [48194](https://www.zsh.org/mla/workers/2021/msg00407.html). I, too, woul= d > prefer this code not to go into the .zshrc file. Would also be resolved by not enabling menu selection :). >>> bindkey -M menuselect -s "$key[Backtab]" "$key[Return]$key[Tab]" >> >> How is this different from ^[a (eg, accept-and-hold) in menu selection? > > accept-and-hold doesn=E2=80=99t work correctly with, for example, directo= ry > completions. To see this for yourself, try `cd /` + Tab + ^[a. Then try `= cd > /` + Tab + Backtab. Notice the difference. The first one makes no sense. In that particular use case I think you would use accept-and-infer-next-his= tory. >>> bindkey -M menuselect "^[$key[Up]" vi-backward-blank-word # Alt-Up: >>> Previous completion group >>> bindkey -M menuselect "^[$key[Down]" vi-forward-blank-word # Alt-Dow= n: >>> Next completion group >> >> So we set WORDCHARS to the empty string, then use the vi widgets >> anyway for good measure? > > These are complist features. It does what it says in the comments: > vi-backward-blank-word moves to the previous completion group in the > completion menu; vi-forward-blank-word moves to the next completion grou= p > in the completion menu. I didn't notice the -M menuselect parts of these, which means a new user probably won't either, should be commented that these apply only to menu selection mode, and possibly all of these should be grouped together if they stay. [snipped some stuff] >>> # Auto-save last 20 dirs to file whenever we change dirs. >>> # See >>> http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Recent-D= irectories >>> autoload -Uz add-zsh-hook chpwd_recent_dirs >>> add-zsh-hook chpwd chpwd_recent_dirs >>> zstyle ':chpwd:*' recent-dirs-file ${ZDOTDIR:-$HOME}/.chpwd-recent-dirs >>> >>> # On startup, initialize dir stack from file. >>> autoload -Uz chpwd_recent_filehandler >>> chpwd_recent_filehandler >>> cd $reply[1] >>> dirs $reply[@] >/dev/null >> >> Does this start zsh in some other directory than it inherited from the >> terminal? If so, nak from me on that, way too surprising. > > It makes the shell pick up in the same dir as where you left off last tim= e. > I would hardly call that surprising. In fact, I would pretty much call th= at > _expected_ for most applications nowadays. I think most people on the list will strongly disagree with you here. >>> ## >>> # Miscellaneous shell options >>> # See http://zsh.sourceforge.net/Doc/Release/Options.html >>> # >>> >>> setopt GLOB_STAR_SHORT # Use `**` for recursive globbing; `***` to >>> also traverse symlinks. >> >> ** and *** already exist without this option, confusingly phrased. > > Sure, I can make that comment longer. There was already a remark about th= at > earlier. I just prefer to keep everything as concise as possible. Usabili= ty > research teaches us that the more text there is, the less likely anyone w= ill > read it. > > >>> # Add some basic command line highlighting. >>> # See >>> http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-H= ighlighting >>> zle_highlight=3D( >>> isearch:fg=3Dblack,bg=3Dyellow # Matched search text >>> paste:none # Yanked/pasted text >>> region:bg=3Dblue # Selected text >>> special:fg=3Dcyan,bold # Unprintable characters >>> suffix:bg=3Dblue # Auto-removable suffix inserted by >>> completion >>> ) >> >> There are many colors, why use the same for the region and the suffix? > > Because it=E2=80=99s familiar from the GUI world: If text looks selected,= then you > expect it to be replaced when you type over it. > > >>> # Use suffix aliases to associate file extensions with commands. >>> # This way, you can open a file simply by typing its name. >>> # See >>> http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#inde= x-alias >>> READNULLCMD=3D'less' # Makes `< foo` do `less < foo`. >>> alias -s txt=3D'<' md=3D'<' # .txt and .md files >>> alias -s log=3D'tail -f' # .log files >> >> Letting the user type < for less is one thing, but you don't really >> save anything by using a shorter command in the rhs of an alias... it >> does doesn't allow the user to type more than one filename. eg: >> % < file1 file2 >> zsh: command not found: file2 >> % less file1 file2 >> file1 (file 1 of 2) lines ?-?/? (END) - Next: file2 > > There=E2=80=99s no harm in it, though, is there? Plus it makes it so you = Don=E2=80=99t > Repeat Yourself. Now you have only variable you need to change when you w= ant > to move from `less` to, say, `bat`. I literally just showed a case where it is strictly worse for no gain other than saving 3 bytes in the startup file. If you want a single parameter to change, there is already $PAGER. > On 6. Apr 2021, at 0.01, Mikael Magnusson wrote: >> >> On 4/5/21, Mikael Magnusson wrote: >>>> bindkey "$key[Backtab]" reverse-menu-complete >>>> bindkey -M menuselect -s "$key[Backtab]" "$key[Return]$key[Tab]" >> >> Also just noticed you have both of these, so if you press shift-tab >> twice it will first do a reverse-menu-complete inserting the last >> match, then if you press it again it accepts it and inserts the first >> match. > > Yeah, perhaps those two don=E2=80=99t really make sense together. I would= like there > to be a completion menu shortcut that inserts the current selection and t= hen > immediately completes again, but that doesn=E2=80=99t really rhyme with > reverse-menu-complete. As mentioned above, this is accept-and-infer-next-history in menu selection (maybe not interactive mode). I realize that I have only made negative comments so far, but I'd like to say that I appreciate that there's no huge list of arbitrary aliases that nobody would ever know about anyway, and other crud (looking at omz). --=20 Mikael Magnusson