on master help sign in
Add shell completion (#2022)

* Add shell completion * Add shell completion to release

commit1fb614443292fe723e764782be560bb2ab3dda4e authorBenedikt Müller <d12bb@posteo.de> dateTue 12 Apr 2022, 10:10 (5 years ago) parent660e0e4
4 files changed+66
.github/workflows/release.yml+2 contrib/completion/hx.bash+23 contrib/completion/hx.fish+12 contrib/completion/hx.zsh+29
.github/workflows/release.yml+2
@@ -206,6 +206,8 @@ jobs:
206206 pkgname=helix-$TAG-$platform
207207 mkdir $pkgname
208208 cp $source/LICENSE $source/README.md $pkgname
209+ mkdir $pkgname/contrib
210+ cp -r $source/contrib/completion $pkgname/contrib
209211 mv bins-$platform/runtime $pkgname/
210212 mv bins-$platform/hx$exe $pkgname
211213 chmod +x $pkgname/hx$exe
contrib/completion/hx.bashnew file+23
@@ -0,0 +1,23 @@
1+#!/usr/bin/env bash
2+# Bash completion script for Helix editor
3+
4+_hx() {
5+ # $1 command name
6+ # $2 word being completed
7+ # $3 word preceding
8+ COMPREPLY=()
9+
10+ case "$3" in
11+ -g | --grammar)
12+ COMPREPLY=($(compgen -W "fetch build" -- $2))
13+ ;;
14+ --health)
15+ local languages=$(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g')
16+ COMPREPLY=($(compgen -W "$languages" -- $2))
17+ ;;
18+ *)
19+ COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar" -- $2))
20+ ;;
21+ esac
22+} && complete -F _hx hx
23+
contrib/completion/hx.fishnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/env fish
2+# Fish completion script for Helix editor
3+
4+set -l langs (hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g')
5+
6+complete -c hx -s h -l help -d "Prints help information"
7+complete -c hx -l tutor -d "Loads the tutorial"
8+complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup"
9+complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
10+complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
11+complete -c hx -s V -l version -d "Prints version information"
12+
contrib/completion/hx.zshnew file+29
@@ -0,0 +1,29 @@
1+#compdef _hx hx
2+# Zsh completion script for Helix editor
3+
4+_hx() {
5+ _arguments -C \
6+ "-h[Prints help information]" \
7+ "--help[Prints help information]" \
8+ "-v[Increase logging verbosity]" \
9+ "-vv[Increase logging verbosity]" \
10+ "-vvv[Increase logging verbosity]" \
11+ "-V[Prints version information]" \
12+ "--version[Prints version information]" \
13+ "--tutor[Loads the tutorial]" \
14+ "--health[Checks for errors in editor setup]:language:->health" \
15+ "-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
16+ "--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
17+ "*:file:_files"
18+
19+ case "$state" in
20+ health)
21+ local languages=($(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g'))
22+ _values 'language' $languages
23+ ;;
24+ grammar)
25+ _values 'action' fetch build
26+ ;;
27+ esac
28+}
29+