From 1fb614443292fe723e764782be560bb2ab3dda4e Mon Sep 17 00:00:00 2001 From: Benedikt Müller Date: Tue, 12 Apr 2022 10:10:21 +0200 Subject: Add shell completion (#2022) * Add shell completion * Add shell completion to release--- contrib/completion/hx.bash | 23 +++++++++++++++++++++++ contrib/completion/hx.fish | 12 ++++++++++++ contrib/completion/hx.zsh | 29 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 contrib/completion/hx.bash create mode 100644 contrib/completion/hx.fish create mode 100644 contrib/completion/hx.zsh (limited to 'contrib') diff --git a/contrib/completion/hx.bash b/contrib/completion/hx.bash new file mode 100644 index 00000000..6371bedb --- /dev/null +++ b/contrib/completion/hx.bash @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Bash completion script for Helix editor + +_hx() { + # $1 command name + # $2 word being completed + # $3 word preceding + COMPREPLY=() + + case "$3" in + -g | --grammar) + COMPREPLY=($(compgen -W "fetch build" -- $2)) + ;; + --health) + local languages=$(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g') + COMPREPLY=($(compgen -W "$languages" -- $2)) + ;; + *) + COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar" -- $2)) + ;; + esac +} && complete -F _hx hx + diff --git a/contrib/completion/hx.fish b/contrib/completion/hx.fish new file mode 100644 index 00000000..4ec690d8 --- /dev/null +++ b/contrib/completion/hx.fish @@ -0,0 +1,12 @@ +#!/usr/bin/env fish +# Fish completion script for Helix editor + +set -l langs (hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g') + +complete -c hx -s h -l help -d "Prints help information" +complete -c hx -l tutor -d "Loads the tutorial" +complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup" +complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars" +complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity" +complete -c hx -s V -l version -d "Prints version information" + diff --git a/contrib/completion/hx.zsh b/contrib/completion/hx.zsh new file mode 100644 index 00000000..16631519 --- /dev/null +++ b/contrib/completion/hx.zsh @@ -0,0 +1,29 @@ +#compdef _hx hx +# Zsh completion script for Helix editor + +_hx() { + _arguments -C \ + "-h[Prints help information]" \ + "--help[Prints help information]" \ + "-v[Increase logging verbosity]" \ + "-vv[Increase logging verbosity]" \ + "-vvv[Increase logging verbosity]" \ + "-V[Prints version information]" \ + "--version[Prints version information]" \ + "--tutor[Loads the tutorial]" \ + "--health[Checks for errors in editor setup]:language:->health" \ + "-g[Fetches or builds tree-sitter grammars]:action:->grammar" \ + "--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \ + "*:file:_files" + + case "$state" in + health) + local languages=($(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g')) + _values 'language' $languages + ;; + grammar) + _values 'action' fetch build + ;; + esac +} + -- cgit v1.2.3-70-g09d2