Skip to content

Instantly share code, notes, and snippets.

@samtay
Created April 18, 2019 17:51
Show Gist options
  • Save samtay/30397d6894c707a315a6c16e3fca77e9 to your computer and use it in GitHub Desktop.
Save samtay/30397d6894c707a315a6c16e3fca77e9 to your computer and use it in GitHub Desktop.
Forward `stack ghci` completions to `ghcid -c 'stack ghci...'`
stack-ghcid()
{
ghcid -c 'stack ghci '"$@"''
}
_stack-ghcid()
{
local CMDLINE
local IFS=$'\n'
export COMP_LINE="${COMP_LINE/stack-ghcid/'stack ghci'}"
export COMP_POINT=$(($COMP_POINT - 1))
export COMP_WORDS=("stack" "ghci" "${COMP_WORDS[@]:1}" )
export COMP_CWORD=$(($COMP_CWORD + 1))
CMDLINE=(--bash-completion-index $COMP_CWORD)
for arg in ${COMP_WORDS[@]}; do
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
done
COMPREPLY=( $(stack "${CMDLINE[@]}") )
}
complete -o filenames -F _stack-ghcid stack-ghcid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment