Quicker Script Access

sabberworm edited this page Aug 7, 2011 · 4 revisions

Tired of having to type base/scripts/*.sh each time you want to call a script? Put the following in your .bash_profile:

function _rap() {
	local cur prev opts
	
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	if [ ! -d base/scripts ]; then
		return 0
	fi
	opts=$( cd base/scripts > /dev/null ; echo * )

	if [[ ${prev} == "rap" ]] ; then
		COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
		return 0
	fi
}
function rap() {
	script_name=$1
	shift
	"./base/scripts/$script_name" "$@"
}
complete -F _rap rap

Now you can just type rap , hit tab and the rest will autocomplete.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.