Browse Source

nixpkgs/elvish: add cobra completion module

Thomas Dy 2 years ago
parent
commit
0617cf3159
1 changed files with 17 additions and 0 deletions
  1. 17 0
      .config/nixpkgs/elvish/lib/cobra.elv

+ 17 - 0
.config/nixpkgs/elvish/lib/cobra.elv

@@ -0,0 +1,17 @@
+use str
+
+fn complete {|command @rest|
+  (external $command) __complete $@rest 2>/dev/null | each {|line|
+    if (str:has-prefix $line ":") {
+      continue
+    }
+
+    var @result = (str:split &max=2 "\t" $line)
+    var name = $result[0]
+    var description = $name
+    if (> (count $result) 1) {
+      set description = $description' ('$result[1]')'
+    }
+    edit:complex-candidate $result[0] &display=$description &code-suffix=' '
+  }
+}