From 1fb614443292fe723e764782be560bb2ab3dda4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCller?= Date: Tue, 12 Apr 2022 10:10:21 +0200 Subject: [PATCH] Add shell completion (#2022) * Add shell completion * Add shell completion to release --- .github/workflows/release.yml | 2 ++ contrib/completion/hx.bash | 23 +++++++++++++++++++++++ contrib/completion/hx.fish | 12 ++++++++++++ contrib/completion/hx.zsh | 29 +++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 contrib/completion/hx.bash create mode 100644 contrib/completion/hx.fish create mode 100644 contrib/completion/hx.zsh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e11d159ff..7c265db8c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -206,6 +206,8 @@ jobs: pkgname=helix-$TAG-$platform mkdir $pkgname cp $source/LICENSE $source/README.md $pkgname + mkdir $pkgname/contrib + cp -r $source/contrib/completion $pkgname/contrib mv bins-$platform/runtime $pkgname/ mv bins-$platform/hx$exe $pkgname chmod +x $pkgname/hx$exe diff --git a/contrib/completion/hx.bash b/contrib/completion/hx.bash new file mode 100644 index 000000000..6371bedb6 --- /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 000000000..4ec690d8b --- /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 000000000..16631519b --- /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 +} +