git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* StGit command completions - and Git ones?
@ 2005-10-02 11:03 Blaisorblade
  2005-10-02 17:37 ` Horst von Brand
  2005-10-04  7:23 ` Catalin Marinas
  0 siblings, 2 replies; 5+ messages in thread
From: Blaisorblade @ 2005-10-02 11:03 UTC (permalink / raw)
  To: Catalin Marinas, git

[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

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

[-- Attachment #2: stg-compl --]
[-- Type: text/plain, Size: 2369 bytes --]

_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:

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-10-04  9:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-02 11:03 StGit command completions - and Git ones? Blaisorblade
2005-10-02 17:37 ` Horst von Brand
2005-10-03 17:57   ` Blaisorblade
2005-10-04  7:23 ` Catalin Marinas
2005-10-04  9:57   ` Blaisorblade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).