Skip to content

How to enable Bash completion for goat v1 shortcuts?

Mateusz Piotrowski edited this page Apr 20, 2018 · 1 revision

This is about goat v1 and doesn't apply to goat v2.

Overview

This is an experimental feature - it will enable shortcut completion when you use goat in Bash. It does not work for cd.

Tested on macOS 10.12.1 running GNU bash, version 4.4.5(1)-release (x86_64-apple-darwin16.3.0).

Installation

  1. Install bash-completion.

  2. Add this code to ~/.bash_completion:

    _goat()
    {
        local cur prev opts
        local kGOAT_SHORTCUTS="$HOME/.goat/shortcuts.config"
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
        opts="$(cut -f1 "$kGOAT_SHORTCUTS" | tr "\n" ' ')"
        if [[ ${cur} == * ]] ; then
            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
            return 0
        fi
    }
    complete -F _goat goat
  3. You might need to source ~/.bashrc.

  4. Enjoy your completion for goat (goat <TAB> should result in a list of your shortcuts).

Resources