DragonBox / u3d

U3d is a cross-platform set of tools to interact with Unity3D from command line.
MIT License
361 stars 33 forks source link

shell autocompletion #224

Open m-ronchi opened 6 years ago

m-ronchi commented 6 years ago

it would be great to add contextual autocompletion features to the options.

i came up with a basic bash script with some stuff (it autocomplete with commands, and with installed versions after the -u flag or uninstall command):

_u3d()
{
    local cur prev commands
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    case o"${prev}" in
        o-u)
            local versions="$(u3d list | sed 's/^Version \([0-9\\.abfp]*\).*$/\1/')"
            COMPREPLY=( $(compgen -W "${versions}" -- ${cur}) )
            return 0
            ;;
        esac

    if [[ i"${COMP_CWORD}" = i1 ]] || [[ i"${COMP_CWORD}"x"${prev}" = i2xhelp ]];then
        commands="available credentials help install list prettify run uninstall"
        COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
        return 0
    fi
    case i"${COMP_CWORD}"x"${prev}" in
        i2xinstall)
            #TODO display fetched versions?? 'u3d available' may need to refresh and be too slow. is there a flag to skip refreshing?
            local versions="latest latest_stable latest_beta latest_patch"
            COMPREPLY=( $(compgen -W "${versions}" -- ${cur}) )
            return 0
            ;;
        i2xuninstall)
            local versions="$(u3d list | sed 's/^Version \([0-9\\.abfp]*\).*$/\1/')"
            COMPREPLY=( $(compgen -W "${versions}" -- ${cur}) )
            return 0
            ;;
    esac
}
complete -F _u3d u3d

installation may be os-dependant, I manually put it into my .bashrc

lacostej commented 6 years ago

@m-ronchi Thanks! We were discussing this a couple of days ago with @niezbop.

Actually we are looking at making a system of plugins (#194). So we might want make it a bit more flexible. We will think about it.