on master help sign in
fix: add elvish completions (#3331)
c2a6d29Alexander Brevig
contrib/completion/hx.elvnew file+49
@@ -0,0 +1,49 @@
1+# You can move it here ~/.config/elvish/lib/hx.elv
2+# Or add `eval (slurp < ~/$REPOS/helix/contrib/completion/hx.elv)`
3+# Be sure to replace `$REPOS` with something that makes sense for you!
4+
5+### Renders a pretty completion candidate
6+var candidate = { | _stem _desc |
7+ edit:complex-candidate $_stem &display=(styled $_stem bold)(styled " "$_desc dim)
8+}
9+
10+### These commands will invalidate further input (i.e. not react to them)
11+var skips = [ "--tutor" "--help" "--version" "-V" "--health" ]
12+
13+### Grammar commands
14+var grammar = [ "--grammar" "-g" ]
15+
16+### Config commands
17+var config = [ "--config" "-c" ]
18+
19+### Set an arg-completer for the `hx` binary
20+set edit:completion:arg-completer[hx] = {|@args|
21+ var n = (count $args)
22+ if (>= $n 3) {
23+ # Stop completions if passed arg will take presedence
24+ # and invalidate further input
25+ if (has-value $skips $args[-2]) {
26+ return
27+ }
28+ # If the previous arg == --grammar, then only suggest:
29+ if (has-value $grammar $args[-2]) {
30+ $candidate "fetch" "Fetch the tree-sitter grammars"
31+ $candidate "build" "Build the tree-sitter grammars"
32+ return
33+ }
34+ # When we have --config, we need a file
35+ if (has-values $config $args[-2]) {
36+ edit:complete-filename $args[-1] | each { |v| put $v[stem] }
37+ return
38+ }
39+ }
40+ edit:complete-filename $args[-1] | each { |v| put $v[stem]}
41+ $candidate "--help" "(Prints help information)"
42+ $candidate "--version" "(Prints version information)"
43+ $candidate "--tutor" "(Loads the tutorial)"
44+ $candidate "--health" "(Checks for errors in editor setup)"
45+ $candidate "--grammar" "(Fetch or build the tree-sitter grammars)"
46+ $candidate "--vsplit" "(Splits all given files vertically)"
47+ $candidate "--hsplit" "(Splits all given files horizontally)"
48+ $candidate "--config" "(Specifies a file to use for configuration)"
49+}