Skip to content

Instantly share code, notes, and snippets.

@dmryabov
Last active June 13, 2018 22:40
Show Gist options
  • Save dmryabov/27b3a6219a2f0ff5d51c53e9be379f20 to your computer and use it in GitHub Desktop.
Save dmryabov/27b3a6219a2f0ff5d51c53e9be379f20 to your computer and use it in GitHub Desktop.
# -*- shell-script -*-
_complete_elixir_iex()
{
local cur prev opts name completion_file
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
name=$1
completion_file="/tmp/.elixir_completion/${name}"
if [[ ! -f $completion_file ]]; then
opts=$(for i in `${name} --help 2>&1 >/dev/null | grep -e '^ *-' | awk '{ print $1 }'`; do echo $i; done)
mkdir -p /tmp/.elixir_completion
echo $opts > $completion_file
else
opts=$(cat $completion_file)
fi
if [[ ${prev} == $name ]] ; then
COMPREPLY=( $(compgen -W "${opts} --help" -- ${cur}) )
return 0
fi
}
_complete_mix()
{
local cur prev opts mix_file completion_file dir_hash
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
mix_file="./mix.exs"
if [[ -f $mix_file ]]; then
dir_hash="$(pwd | sha256sum | head -c 64)"
else
dir_hash="global"
fi
completion_file="/tmp/.elixir_completion/mix_${dir_hash}"
if [[ ! -f $completion_file ]] || [[ $mix_file -nt $completion_file ]]; then
opts=$(for i in `mix help | grep -ve "current:" | grep -ve "iex" | awk '{ print $2" " }'`; do echo $i; done)
mkdir -p /tmp/.elixir_completion
echo $opts > $completion_file
else
opts=$(cat $completion_file)
fi
if [[ ${prev} == mix ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -f -F _complete_elixir_iex elixir iex
complete -F _complete_mix mix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment