Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
111 lines (88 sloc) 4.15 KB

Elvish completions for various built-in commands

Completions for some of Elvish’s built-in commands, including use, the epm module and elvish itself.

This file is written in literate programming style, to make it easy to explain. See $name.elv for the generated file.

Table of Contents

Usage

Install the elvish-modules package using epm:

use epm
epm:install github.com/zzamboni/elvish-completions

In your rc.elv, load this module:

use github.com/zzamboni/elvish-completions/builtins

Included completions:

  • elvish (completes command-line options and .elv files).
  • use (completes all modules in ~/.elvish/lib). Example (the “lack module name” message is normal and part of Elvish’s as-you-type compilation, it goes away when you add a module name):
    [~]─> use <Tab>
     COMPLETING argument _
    compilation error: 3-3 in [tty]: lack module name
     elvish-dev/epm/epm                               github.com/zzamboni/elvish-modules/alias
     github.com/iwoloschin/elvish-packages/powernerd  github.com/zzamboni/elvish-modules/atlas
     github.com/iwoloschin/elvish-packages/python     github.com/zzamboni/elvish-modules/bang-bang
     github.com/iwoloschin/elvish-packages/update     github.com/zzamboni/elvish-modules/dir
     github.com/muesli/elvish-libs/git                github.com/zzamboni/elvish-modules/git-vcsh
     github.com/muesli/elvish-libs/theme/muesli       github.com/zzamboni/elvish-modules/long-running-notifications
     github.com/muesli/elvish-libs/theme/powerline    github.com/zzamboni/elvish-modules/nix
     github.com/xiaq/edit.elv/compl/go                github.com/zzamboni/elvish-modules/opsgenie
     github.com/xiaq/edit.elv/smart-matcher           github.com/zzamboni/elvish-modules/prompt-hooks
     github.com/zzamboni/elvish-completions/builtins  github.com/zzamboni/elvish-modules/proxy
     github.com/zzamboni/elvish-completions/cd        github.com/zzamboni/elvish-modules/semver
     github.com/zzamboni/elvish-completions/comp      github.com/zzamboni/elvish-modules/terminal-title
     github.com/zzamboni/elvish-completions/git       github.com/zzamboni/elvish-modules/util
     github.com/zzamboni/elvish-completions/ssh       github.com/zzamboni/elvish-themes/chain
     github.com/zzamboni/elvish-completions/vcsh      private
        
  • epm commands: completes installed packages for the appropriate commands.

Implementation

Load the completion framework and other libraries.

use ./comp
use re

use

Completer for the use command, which includes all modules in ~/.elvish/lib/.

edit:completion:arg-completer[use] = (comp:sequence [{
    put ~/.elvish/lib/**[nomatch-ok].elv | each [m]{
      if (not (-is-dir $m)) {
        re:replace ~/.elvish/lib/'(.*).elv' '$1' $m
      }
    }
  }]
)

epm

Completers for the epm commands.

use epm

epm-completer-one  = (comp:sequence [ $epm:list~ ])
epm-completer-many = (comp:sequence [ $epm:list~ ...])
edit:completion:arg-completer[epm:query]     = $epm-completer-one
edit:completion:arg-completer[epm:metadata]  = $epm-completer-one
edit:completion:arg-completer[epm:dest]      = $epm-completer-one
edit:completion:arg-completer[epm:uninstall] = $epm-completer-many
edit:completion:arg-completer[epm:upgrade]   = $epm-completer-many

elvish

Completer for the elvish command.

edit:completion:arg-completer[elvish] = (comp:sequence ^
  &opts= { elvish -help | comp:extract-opts &fold } ^
  [ [arg]{ comp:files $arg &regex='\.elv$' } ] ^
)
You can’t perform that action at this time.