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 9735 invoked from network); 7 Apr 2021 14:29:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Apr 2021 14:29:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617805747; b=KGdD2fsrDqQ+JZLbriRtQzUm/FQMYFd6NPY1+aiNPfUYeBkgBqWVAGubV93Qt9k9aFhciSaKp+ 3iWWnB/ttLYgy51acY//UnIduooQMjrHQAdhszEodU3VDonb3T8DFrGvnWK3BiDyeeqe48COuu pgeB6bTk0gTlJG/c4sit70SMfyd//XudgUkU9WDEurhDIuZHdxkFP4dXhjkTd9nZPmabWr/NIL 9YSZyVDLkH8DeG5C7nx0UHCNKG/lr61YOca3IsYcgj8FJpt87Rxk+S5VbaLYoTTCJ4aYeOlgxq C8UP0LaxcPh1jzhilC82y3XrQaNyvV+jEOYmiU9uEvfz2g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; 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=1617805747; bh=kxrnaWPH56hx9JmYzK48jnurfsy04coqcEXr7mL0uGY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:References:Message-ID:Content-Transfer-Encoding:Cc:Date: In-Reply-To:From:Subject:MIME-Version:Content-Type:DKIM-Signature: DKIM-Signature; b=ZmjpJPNym6mJEBd/kzWGJwJReCmLWbwKMr8w4J26OrQRqO8l6TnaJRwHOvpENhOyzD2spDvekq HPeSGqQHbrzYFgrpeiSEDCyG+Duj5ye9ugF1/zSYTYkcFYSi3ZktWJR1S5nGCPSyxnsbN5tqoB 462+HyHkWIQcjpsY7VA8LGaiHLxOGnWkxnFS5arnEW2SWhNoKDMHFLGBGPJ8eWQ1Z8QcIQxMOO 7EVeKrUx4ueO5GE2fsEfMzP4hDk80sQLQEaXS2fxY/xruxsjVJEG0HNJenUbWBoqTElHYvd6H2 qO4uoYVMc/3+2FVEkMKWlXYpu+gHPU9MOfrkwP7S7YbBWQ==; 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:To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=xIdPvYLi3o47Wql+a2DePgYlvqqYJPOXSC0d1lXUhjQ=; b=OzMxGc8LpCTLtnOCuTEHG9YDMm urk3Fcui9fi5YOHFIc6NMH7SC4ER90ZAT/ZGq5/HrNJi9eNyyJnPBrQFpJyf300/ggpqjLEEd5L1H q8H6JwEyM9j2s/pUdol9jSk8671j0XJ9aQFlBKC8/5s2N+Ok1Avsh2orkVyjE9FZQn0eRay5KlQAg rJa2fgR7jKdBWx5s/gr4nTKDzBcYzM7PRdVUnoxD3tnqpxjIlMMMoHgHKef1aHSFfsotKjV13QKp2 C189Vu3wfJuhds5EjiEZ7JCbh97GMib2w87sfaZAZDztV74g3513L+nO6BXij218UbdJuGCOlfETN nnadBSiA==; Received: from authenticated user by zero.zsh.org with local id 1lU9B2-000JGQ-DO; Wed, 07 Apr 2021 14:29:04 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f179.google.com ([209.85.208.179]:42868) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lU9AV-000J20-PU; Wed, 07 Apr 2021 14:28:32 +0000 Received: by mail-lj1-f179.google.com with SMTP id 184so20925650ljf.9 for ; Wed, 07 Apr 2021 07:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=xIdPvYLi3o47Wql+a2DePgYlvqqYJPOXSC0d1lXUhjQ=; b=bTXxxwv3/FGFEmszxBEV83xSvlWIGr4ofjE3c3XIN8M+ItoARfd9dAgJOffArXiKG3 BwP1SQ+qx6JmfUT6Eqw9S5qMsgxZiq6aLxm1NtYLjYceEfgnfcga12P+0kDaAfez5jXF dA4YZvdgxGcP+NHjsHRpsyLJgPxmJnAf0JSwfKFkQPFItTc+1DssWNAPukHxmupUDX2a lWTqPIE4wj/Irpr9bZjxS2BkNWrUhbpdkJ0ZLtGSQNU4y+UIdQ6G7yHqE8KoMakKtrZJ lfSAG/c/aI2g7YFHJGcRtlItnOlQELZocIvPIpKkBOnh+Yk9PAaWPrei8eODriOudiMh iweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=xIdPvYLi3o47Wql+a2DePgYlvqqYJPOXSC0d1lXUhjQ=; b=ixw+YhQU1N1OkHCb2/yE9MZnrv6Nmd+UnaGN/UUQfpWG8AK/L9JdswTaGDLJYhfCFR +3A7TEjc/eubxIx8nIFT+ixknQJKx1uZ9AQMN6kditUBaFfEtkoEOyw6hzR7rfrYrMje MjauZ1V/MCddKNmr9cC2aRQ+xBwENIZEZFpkzk9OsmTpgXB+TlotXVdkwAhyVUaSUWK+ fEXLx82JZr8CMY+AmAWk5LgPnnCoXSjQKXsgIigLW69Ud7F+VwcvC5cRWfNHfSugBFdK 2m9TQcYGzGODeDv4W94tLeFo659KrpM0rZNyK3T8hig76aqyqBxMhVUswkTrMV5/wohi 5gjw== X-Gm-Message-State: AOAM533mGRqfw1ph+fD1viFjFi38AebY7wg429ZNu7ePS2XX0omdFAWc jk9gTc3BglyacJAxixxyJoQ= X-Google-Smtp-Source: ABdhPJwxxo1n6uayInQCCrZmWMQpN/R83vvk5uM9za52X1D9C8reJA6VprDaPC2nfXaBsWnzmvdtFg== X-Received: by 2002:a05:651c:28b:: with SMTP id b11mr2320881ljo.219.1617805710969; Wed, 07 Apr 2021 07:28:30 -0700 (PDT) Received: from [192.168.1.15] (hag-tkubng22-50df3e-132.dhcp.inet.fi. [80.223.62.132]) by smtp.gmail.com with ESMTPSA id v20sm2476649ljh.105.2021.04.07.07.28.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 07:28:30 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: Rewrite of zsh-newuser-install (Mikael's subthread) From: Marlon In-Reply-To: Date: Wed, 7 Apr 2021 17:28:29 +0300 Cc: Zsh hackers list Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Mikael Magnusson X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48419 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 5. Apr 2021, at 22.44, Mikael Magnusson wrote: >=20 > 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 >>=20 >> print -P 'Restarting Zsh...' >> zsh -l && >> exit >> } >=20 > 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 = me. I did not come up with the -l, though. Earlier in the thread, Oliver = & Bart didn=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=99= d be happy to change it, but I don=E2=80=99t know how they feel about = it. >> setopt EXTENDED_HISTORY # Save each command's time & duration = to 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. >=20 > 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. >> # 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} >=20 > These two lines don't actually bind any keys, but the comment claims = they 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. >> # Delete: Delete one character to the right or, if that's not = possible, list completions. >> # If the list is too long to fit on screen, then start type-ahead = search. >> bindkey "$key[Delete]" delete-char-or-list >> zle -C {,.}delete-char-or-list _generic >> zstyle ':completion:delete-char-or-list:*:default' menu yes = select=3Dlong-list interactive >=20 > This is a very unintuitive keybind, I realize that ctrl-d does this, > but I would never expect the delete key to do it. Also see later > comment about menu selection being force enabled. Sure, I can make it do just delete. >> # Tab/Shift-Tab: Start type-ahead completion. >> # * Tab: Insert substring shown by `interactive: = []`. >> # * Shift-Tab: Accept selection & start next completion. >=20 > 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 = prefix doesn=E2=80=99t exist. However, I don=E2=80=99t want to override = the defaults when I can avoid it. 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 `interactive` = mode. Also, in complist=E2=80=99s `interactive` mode, Tab does _not_ cycle = forward, but inserts =E2=80=9Cunambiguous". Ergo, in this context, I = would _not_ expect to Backtab to cycle backwards. >> # * Arrow keys: Change selection. >> # * Enter: Accept selection & stop completing. >> zstyle ':completion:(|reverse-)menu-complete:*:default' menu yes = select interactive >=20 > 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. = Instead, it enables type-ahead completion, which is an extremely useful = complist feature. >> bindkey "$key[Tab]" menu-complete >> zle -C {,.}menu-complete _generic >> bindkey "$key[Backtab]" reverse-menu-complete >> zle -C {,.}reverse-menu-complete _generic >=20 > 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 = disable 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, would prefer this code not to go into the .zshrc file. >=20 >> bindkey -M menuselect -s "$key[Backtab]" "$key[Return]$key[Tab]" >=20 > 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, = directory completions. To see this for yourself, try `cd /` + Tab + ^[a. = Then try `cd /` + Tab + Backtab. Notice the difference. The first one = makes no sense. >> bindkey -M menuselect "^[$key[Up]" vi-backward-blank-word # = Alt-Up: Previous completion group >> bindkey -M menuselect "^[$key[Down]" vi-forward-blank-word # = Alt-Down: Next completion group >=20 > 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 = group in the completion menu. >> # Highlight next differentiating character. >> zstyle ':completion:*:default' show-ambiguity = "$color[black];$color[bg-yellow]" >=20 > I disagree with using this, it disables colored filetypes doesn't it? Only when there is an =E2=80=9Cunambiguous=E2=80=9D prefix that can be = inserted. But I guess since we use `interactive` complist, this isn=E2=80=99= t really necessary. I will remove it. >> setopt PUSHD_MINUS # `~-` + Tab: Select a = dir stack entry. >> bindkey -s "^[$key[Up]" "^Q..$key[Return]" # Alt-Up: Up to = parent dir. >> bindkey "^[$key[Down]" menu-select # Alt-Down: Select a = local dir or file. >> zle -C {,}menu-select _generic >=20 > More random default completion widgets changing even though we are > long done with completion settings... No, I=E2=80=99m just creating two handy, generic widgets here. Using the = completion system for it is just an implementation detail. But I can = move those, too, into an autoloadable function; no problem. >> zstyle ':completion:menu-select:*:-command-:*' tag-order \ >> 'globbed-files executables (|local-)directories suffix-aliases' - >> zstyle ':completion:menu-select:*' tag-order '(|*-)directories = (|*-)files' - >=20 > these two need comments Sure, I=E2=80=99ll add. >> # Auto-save last 20 dirs to file whenever we change dirs. >> # See = http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Recent-Dire= ctories >> 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 >>=20 >> # On startup, initialize dir stack from file. >> autoload -Uz chpwd_recent_filehandler >> chpwd_recent_filehandler >> cd $reply[1] >> dirs $reply[@] >/dev/null >=20 > 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 = time. I would hardly call that surprising. In fact, I would pretty much = call that _expected_ for most applications nowadays. >> ## >> # Miscellaneous shell options >> # See http://zsh.sourceforge.net/Doc/Release/Options.html >> # >>=20 >> setopt GLOB_STAR_SHORT # Use `**` for recursive globbing; `***` to = also traverse symlinks. >=20 > ** and *** already exist without this option, confusingly phrased. Sure, I can make that comment longer. There was already a remark about = that earlier. I just prefer to keep everything as concise as possible. = Usability research teaches us that the more text there is, the less = likely anyone will read it. >> # Add some basic command line highlighting. >> # See = http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-High= lighting >> 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 >> ) >=20 > 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#index-a= lias >> 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 >=20 > 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 want to move from `less` to, say, `bat`. On 6. Apr 2021, at 0.01, Mikael Magnusson wrote: >=20 > On 4/5/21, Mikael Magnusson wrote: >>> bindkey "$key[Backtab]" reverse-menu-complete >>> bindkey -M menuselect -s "$key[Backtab]" "$key[Return]$key[Tab]" >=20 > 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 then immediately completes again, but that = doesn=E2=80=99t really rhyme with reverse-menu-complete.