u3d icon indicating copy to clipboard operation
u3d copied to clipboard

shell autocompletion

Open m-ronchi opened this issue 8 years ago • 1 comments

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

m-ronchi avatar Jan 11 '18 10:01 m-ronchi

@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.

lacostej avatar Jan 11 '18 15:01 lacostej