StGit command completions - and Git ones?

From: Blaisorblade <blaisorblade@yahoo.it>
Date: 2005-10-02 21:03:44
I noticed in your TODO you talk about adding command line completions. I've 
been doing it for my needs, and the thing is still very incomplete, even if 
it's not a "XXX hack hack hack", and I wanted to send this first draft.

Note: I've not tried to add any completion which isn't StGit specific:
a) I didn't need them

b) they should be implemented for git and cogito first

c) not everything is clear. For instance, I think that SHA1 completion is 
pretty useless (I never type a SHA1), while only branch and tag completion 
is, but maybe other disagree: there's support for it in Cogito, in fact, and 
a shortened SHA1 is used as kernel revision.

-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade

_stg () 
{
	local cur cmd cmds 
	cur=${COMP_WORDS[COMP_CWORD]}
	COMPREPLY=()
	if [ $COMP_CWORD -eq 1 ]; then
		cmds=$(stg help|tail +4|awk '{print $1}')
		COMPREPLY=( $(compgen -W "${cmds}" -- $cur) )
	else
		local cmd=${COMP_WORDS[1]}
		local prev=${COMP_WORDS[COMP_CWORD-1]}
		#if [ $COMP_CWORD -eq 2 -o "$prev" = "-t" -o "$prev" = "--to" -o "$prev" = "-r" ]; then
		local patches
		#Add -b support - pass "-b branch" to unapplied and applied.
		case $cmd in
			push)
			patches=$(stg unapplied)
			;;
			pop|mail)
			patches=$(stg applied)
			;;
			diff|id)
			patches=$((stg applied; stg unapplied)|while read i; do echo $i/; done)
			;;
		esac
		case $cmd in
			push)
			if [ "$prev" = "-t" -o "$prev" = "--to" ]; then
				if [ "${cur#*:}" != "${cur}" ]; then
					COMPREPLY=( $(compgen -W "${patches}" -- ${cur#*:}) )
				else
					COMPREPLY=( $(compgen -W "${patches}" -- $cur) )
				fi
			else
				cmds="-a --all -n --number -t --to --reverse --undo -h --help"
				COMPREPLY=( $(compgen -W "${cmds} ${patches}" -- $cur) )
			fi
			;;

			pop)
			if [ "$prev" = "-t" -o "$prev" = "--to" ]; then
				COMPREPLY=( $(compgen -W "${patches}" -- $cur) )
			else
				cmds="-a --all -n --number -t --to -h --help"
				COMPREPLY=( $(compgen -W "${cmds}" -- $cur) )
			fi
			;;

			mail)
			if [ "$prev" = "-r" -o "$prev" = "--range" ]; then
				if [ "${cur#*:}" != "${cur}" ]; then
					COMPREPLY=( $(compgen -W "${patches}" -- ${cur#*:}) )
				else
					COMPREPLY=( $(compgen -W "${patches}" -- $cur) )
				fi
			else
				cmds="-a --all -r --range --to --cc --bcc -v --version \
				-t --template -f --first -s --sleep --refid -u --smtp-user \
				-p --smtp-password -b --branch -h --help"

				COMPREPLY=( $(compgen -o bashdefault -W "${cmds} ${patches}" -- $cur) )
			fi
			;;
			diff)
			if [ "$prev" = "-r" ]; then
				if [ "${cur#*:}" != "${cur}" ]; then
					COMPREPLY=( $(compgen -W "${patches}" -- ${cur#*:}) )
				else
					COMPREPLY=( $(compgen -W "${patches}" -- $cur) )
				fi
			else
				cmds="-r -s --stat -h --help"

				COMPREPLY=( $(compgen -W "${cmds}" -- $cur) )
			fi
			;;
			id)
				cmds="-b --branch -h --help"
				COMPREPLY=( $(compgen -W "${cmds} ${patches}" -- $cur) )
			;;
			*)
			COMPREPLY=( $(compgen -f -- $cur) )
			;;
		esac
		#else
			#COMPREPLY=( $(compgen -f -- $cur) )
		#fi
	fi
}

complete -o default -F _stg stg

# vi: set ft=sh:


	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Sun Oct 02 21:04:48 2005

This archive was generated by hypermail 2.1.8 : 2005-10-02 21:04:50 EST