Skip to content

Latest commit

 

History

History
55 lines (48 loc) · 1.85 KB

vcsh.org

File metadata and controls

55 lines (48 loc) · 1.85 KB

Elvish completions for vcsh

Completions for vcsh.

Implementation

# Completer for vcsh - https://github.com/RichiH/vcsh
# Diego Zamboni <diego@zzamboni.org>

use ./git
use re

# Return all elements in $l1 except those who are already in $l2
fn -all-except {|l1 l2|
  each {|x| if (not (has-value $l2 $x)) { put $x } } $l1
}

fn vcsh-completer {|cmd @rest|
  var n = (count $rest)
  var repos = [(vcsh list)]
  if (eq $n 1) {
    # Extract valid commands and options from the vcsh help message itself
    var cmds = [(vcsh 2>&1 | grep '^   [a-z-]' | grep -v ':$' | awk '{print $1}')]
    put $@repos $@cmds
  } elif (and (> $n 1) (has-value $repos $rest[0])) {
    put (git:git-completer $cmd" "$rest[0] (all $rest[1..]))
  } elif (eq $n 2) {
    # Subcommand- or option-specific completions
    if (eq $rest[0] "-c") {
      put (edit:complete-filename $rest[1])
    } elif (re:match "delete|enter|rename|run|upgrade|write-ignore|list-tracked" $rest[0]) {
      put $@repos
    } elif (eq $rest[0] "list-untracked") {
      put $@repos "-a" "-r"
    } elif (eq $rest[0] "status") {
      put $@repos "--terse"
    }
  } elif (> $n 2) {
    # For more than two arguments, we recurse, removing any options that have been typed already
    # Not perfect but it allows completion to work properly after "vcsh status --terse", for example,
    # without too much repetition
    put (-all-except [(vcsh-completer $cmd (all $rest[0:(- $n 1)]))] $rest[0:(- $n 1)])
  }
}

set edit:completion:arg-completer[vcsh] = $vcsh-completer~