-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shell completions for Bash and Zsh (#591)
- Loading branch information
1 parent
e486fdf
commit d45a6ac
Showing
6 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ logs | |
|
||
# Ignore elvis escript | ||
elvis | ||
!priv/bash_completion/elvis | ||
!priv/zsh_completion/_elvis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2207 # Prefer mapfile or read -a to split command output (or quote to avoid splitting) | ||
|
||
# Bash completion for Elvis, the Erlang style reviewer | ||
_elvis() { | ||
local cur prev | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD - 1]}" | ||
|
||
if [[ ${prev} == "--config" ]] || [[ ${prev} == "rock" ]]; then | ||
local files_and_dirs=($(compgen -f -- "${cur}")) | ||
for item in "${files_and_dirs[@]}"; do | ||
if [[ -d "${item}" ]]; then | ||
compopt -o nospace | ||
COMPREPLY+=("${item}/") | ||
else | ||
COMPREPLY+=("${item}") | ||
fi | ||
done | ||
return 0 | ||
elif [[ ${prev} == "--code_path" ]]; then | ||
compopt -o nospace | ||
COMPREPLY=($(compgen -d -- "${cur}")) | ||
elif [[ ${prev} == "install" ]]; then | ||
COMPREPLY=($(compgen -W "git-hook" -- "${cur}")) | ||
elif [[ ${prev} == "--output_format" ]]; then | ||
COMPREPLY=($(compgen -W "plain colors parsable" -- "${cur}")) | ||
elif [[ ${prev} == "--parallel" ]]; then | ||
COMPREPLY=($(compgen -W "auto" -- "${cur}")) | ||
elif [[ ${prev} == "git-branch" ]]; then | ||
COMPREPLY=($(compgen -W "$(git branch --format='%(refname)' | sed 's|refs/heads/||' || true)" -- "${cur}")) | ||
else | ||
COMPREPLY=($(compgen -W '--help --config --commands git-branch git-hook install rock --output_format --parallel --quiet --verbose --version --code_path --keep_rocking' -- "${cur}")) | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
complete -F _elvis elvis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#compdef elvis | ||
|
||
# Bash completion for Elvis, the Erlang style reviewer | ||
|
||
_elvis() { | ||
local -a commands | ||
local -a formats | ||
local -a parallel_opts | ||
local -a branches | ||
local cur prev | ||
|
||
cur="${1}" | ||
prev="${2}" | ||
|
||
commands=( | ||
'--help[Show help information]' | ||
'--config[Provide path to a non-default configuration file]' | ||
'--commands[Show available commands]' | ||
'git-branch[Execute on files changed since <branch> or <commit>]' | ||
'git-hook[Execute on the pre-commit hook Git-staged files]' | ||
'install[Install as a Git pre-commit hook]' | ||
'rock[Execute on identified files]' | ||
'--output_format[Control the output format]' | ||
'--parallel[Analyze files concurrently]' | ||
'--quiet[Suppress all output]' | ||
'--verbose[Enable verbose output]' | ||
'--version[Show the current version]' | ||
'--code_path[Add <dir> to analysis code path]' | ||
'--keep_rocking[Don’t stop on errors]' | ||
) | ||
|
||
formats=( | ||
'plain[Plain text output]' | ||
'colors[Colored output]' | ||
'parsable[Output suitable for parsing]' | ||
) | ||
|
||
parallel_opts=( | ||
'auto[Automatically determine parallelism]' | ||
'n[Specify number of parallel processes]' | ||
) | ||
|
||
if [[ "$prev" == "--config" ]]; then | ||
_files | ||
elif [[ "$prev" == "--code_path" ]]; then | ||
_files -d | ||
elif [[ "$prev" == "--output_format" ]]; then | ||
_describe -t formats | ||
elif [[ "$prev" == "--parallel" ]]; then | ||
_describe -t parallel 'Parallel options' parallel_opts | ||
elif [[ "$prev" == "git-branch" ]]; then | ||
branches=($(git branch --format='%(refname)' | sed 's|refs/heads/||' || true)) | ||
_describe -t branches 'Git branches' branches | ||
elif [[ "$prev" == "install" ]]; then | ||
_describe -t install 'Install commands' 'git-hook' | ||
elif [[ "$prev" == "rock" ]]; then | ||
_files | ||
else | ||
_describe -t commands 'elvis commands' commands | ||
fi | ||
} | ||
|
||
compdef _elvis elvis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters