#!/bin/bash

# make zsh emulate bash if necessary
if [[ -n "$ZSH_VERSION" ]]; then
    autoload bashcompinit
    bashcompinit
fi


# autocompletion
_goto_completions() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--for --future --implementation"

    if [[ ${prev} == "goto" ]] || [[ ${prev} == "show" ]] || [[ ${prev} == "copy" ]] || [[ ${prev} == "cd" ]] || [[ ${prev} == "rm" ]] || [[ ${prev} == "-o" ]] || [[ ${prev} == "open" ]] || [[ ${prev} == "--open" ]]; then 
        COMPREPLY=( $(compgen -W "$(goto list)" ${cur}) )
        return 0
    fi

    if [[ ${cur} == --* ]] ; then
            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -o default -F _goto_completions goto


_project_completions() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    if [[ ${prev} == "project" || ${prev} == "rm" ]]; then 
        COMPREPLY=( $(compgen -W "$(project list)" ${cur}) )
        return 0
    fi
}
complete -F _project_completions project


#make it possible to cd
function goto {
	# jump around in browser or in terminal
	source goto $@
}
