From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24891 invoked by alias); 6 Nov 2016 02:01:32 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22093 Received: (qmail 23884 invoked from network); 6 Nov 2016 02:01:32 -0000 X-Qmail-Scanner-Diagnostics: from mail-yb0-f182.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.213.182):SA:0(0.0/5.0):. Processed in 0.874778 secs); 06 Nov 2016 02:01:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.213.182 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=IgA9tE0KPbKYGAx5eTv7zyaIbcj3IRzl1044ByvKDh8=; b=qNGfiudGA4z7eio/4BQc9aED/qH08TVZlzoY3zaSDzPxmzV7gIFI+FvnIJiKxNhXcr Pqgx8rKYlZcltL8uAWfzJ2qWt0jufgBIyCNY0jiRnKAchfyOfuAKiWaVgjrW3xX1i/0f m6pPrsh197Yw4BnYQHQBepnXsjt6INDowRjJcYjov8l8cJJUoVagm3KBsJTkAx2Gawya 4FlTqFTeB1L9kigDfyD/BntebEIB+AH+OCu3d1IriyncUSsxAn1OJ/rnC04bFjixFYeE 7X5VlTrkmc3Slz8CGubk3ylvCFY7naATbyjQ1YqLvkilcevfUtM2QSXKrbUeojd3XSbd b3oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=IgA9tE0KPbKYGAx5eTv7zyaIbcj3IRzl1044ByvKDh8=; b=IW1y184UhVOQ7BdJhuP/79zjYnIqn7+RglU73Xfy0CjLmyX8wS3j9hBTLJCBFjemRg ho8bbG57bhSdeiWv7w+u34hGirTZjUipFpWZEEGTL4Tu2sr4cDNw8FqUDS8X7vHnQEQ3 iuwDf3UEtxHHBPqnSUlmXaIFvnz3oXlzvFnDWmyy4abQjI80Q/E5FjsI13Brjr7W7VBD to+7F7jJm7UI8EumCH61JDxqNTRZnkaQFLbf+9E4YqTJ04xBvjd+cWHBjIG4arf+66gK zgneEmrILyxTW0Wxio/IzCcTGYWChaMrR6N1xdf+8rTsHAevPQmLgToEckBPU7hUxWNr d4Iw== X-Gm-Message-State: ABUngveT3mYZ3jylOqazP59a1GjyEE/J96WJkCMAEoT+dv8M2Bpj0ndgOotzlvAusf47lg== X-Received: by 10.37.51.9 with SMTP id z9mr398302ybz.159.1478397678951; Sat, 05 Nov 2016 19:01:18 -0700 (PDT) From: Bart Schaefer Message-Id: <161105190150.ZM1605@torch.brasslantern.com> Date: Sat, 5 Nov 2016 19:01:50 -0700 In-Reply-To: <20161103071706.GA24640@kybu.org> Comments: In reply to ml@kybu.org "Menu completion on empty line" (Nov 3, 7:17am) References: <20161103071706.GA24640@kybu.org> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: ml@kybu.org, Zsh Users Subject: Re: Menu completion on empty line MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Nov 3, 7:17am, ml@kybu.org wrote: } } If I press the tab key on an empty line and I am in a build directory, } which can be detected by a presence of, let's say the makefile file, } it would be useful to get a menu with items: clean build rebuild. I } could use the tab key to move around these items. If I choose one, it } would expand to a particular command, like 'make clean'. As a prelude, there are two problems with this. (1) Completion is VERY single-word-oriented. Anything that completes to something with spaces in it is going to be quoted by default, so you have to jump through even more hoops than usual to make it work. I would recommend avoiding this by creating three aliases alias clean='make clean' alias build='make all' alias rebuild='clean;build' and then use the menu to select those aliases. (2) By default TAB doesn't do anything on an empty command line except insert itself. To fix that, you need: zstyle ':completion::*' insert-tab 'pending=1' With that out of the way ... There are two approaches here: Change the widget invoked by the TAB key, or change the handling for the context of an empty line. The former would let you do the hoop-jumping to insert multiple words as the completion, but the latter is probably what you want to do. To get started, note that with compinit loaded you can always type control-x h to get a description of the current context. If you do that on a blank line, you get: tags in context :completion::complete:-command-:: commands builtins functions aliases suffix-aliases reserved-words jobs parameters (_command_names _autocd) commands (_path_commands _command_names _autocd) jobs (_jobs _command_names _autocd) parameters (_parameters _command_names _autocd) This is telling you that: * the start of an empty line is the special "-command-" context; * there are eight tags recognized in this context; * there are five completion functions that may supply candidate completions for these tags, and which functions use which tags. The important thing in this case is that you would want to change the handling of the -command- context. Here again you have two choices: Replace the default completion function for -command-, or augment one of the existing tags. I'll note at this point that your three aliases show up in the "aliases" tag automatically, and if that were good enough we just stop here. But you want special handling if there's a makefile, so on we go. There is an example in the documentation of supplementing a context. It's found under the fake-always style and discusses the context of the "cd" command. We need to change it to the context we care about. # Create a preferred aliases-make tag for build commands zstyle ':completion::*:-command-::' \ tag-order 'aliases:-make:"build\ commands"' '*' The "*" there in place of "complete" makes this work for other completers, though that's not strictly necessary. The additional '*' in the style definition means that if there is something on the line and it does not match one of those three aliases, you'll get normal completion. Next: # Ignore everything but our three aliases for make zstyle ':completion::*:-command-:*:aliases-make' \ ignored-patterns '*~(clean|build|rebuild)' Now if you press TAB on an empty line, you'll see only your three aliases. To limit it so this happens only when there is a makefile present, we need to use "zstyle -e": # Create a preferred aliases-make tag for build commands # but do so only when there is a makefile in this directory zstyle -e ':completion::*:-command-::' \ tag-order '[[ -f makefile || -f Makefile ]] && reply=("aliases:-make:build\ commands" "*")' And there you have it. -- Barton E. Schaefer