* 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
* Re: StGit command completions - and Git ones?
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
1 sibling, 1 reply; 5+ messages in thread
From: Horst von Brand @ 2005-10-02 17:37 UTC (permalink / raw)
To: Blaisorblade; +Cc: Catalin Marinas, git
Blaisorblade <blaisorblade@yahoo.it> wrote:
> 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.
Why don't just lay this at the bash-completion people's feet?
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: StGit command completions - and Git ones?
2005-10-02 17:37 ` Horst von Brand
@ 2005-10-03 17:57 ` Blaisorblade
0 siblings, 0 replies; 5+ messages in thread
From: Blaisorblade @ 2005-10-03 17:57 UTC (permalink / raw)
To: Horst von Brand; +Cc: Catalin Marinas, git
On Sunday 02 October 2005 19:37, Horst von Brand wrote:
> Blaisorblade <blaisorblade@yahoo.it> wrote:
> > 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.
> Why don't just lay this at the bash-completion people's feet?
Catalin put this in his TODO, and many projects install their additional bash
completions on their own, at least from the Gentoo user point of view.
In any case, I guess I'd rather contact them only when the work is at least
complete.
--
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
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: StGit command completions - and Git ones?
2005-10-02 11:03 StGit command completions - and Git ones? Blaisorblade
2005-10-02 17:37 ` Horst von Brand
@ 2005-10-04 7:23 ` Catalin Marinas
2005-10-04 9:57 ` Blaisorblade
1 sibling, 1 reply; 5+ messages in thread
From: Catalin Marinas @ 2005-10-04 7:23 UTC (permalink / raw)
To: Blaisorblade; +Cc: git
On 02/10/05, Blaisorblade <blaisorblade@yahoo.it> wrote:
> 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.
Thanks, I will have a look at it.
FYI, the tla-contrib package has a script which automatically
generates the bash completion script from the help messages (well,
only for tla, but can be adapted).
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: StGit command completions - and Git ones?
2005-10-04 7:23 ` Catalin Marinas
@ 2005-10-04 9:57 ` Blaisorblade
0 siblings, 0 replies; 5+ messages in thread
From: Blaisorblade @ 2005-10-04 9:57 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]
On Tuesday 04 October 2005 09:23, Catalin Marinas wrote:
> On 02/10/05, Blaisorblade <blaisorblade@yahoo.it> wrote:
> > 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.
>
> Thanks, I will have a look at it.
If you haven't yet, here's today's version.
> FYI, the tla-contrib package has a script which automatically
> generates the bash completion script from the help messages (well,
> only for tla, but can be adapted).
Yes, I wanted to do something like that to speed things up...
if possible, I'd also like to generate option lists from help messages but
that doesn't seem so obvious (not much thought on this, though).
Finally, I'd like to reimplement directly stg applied and unapplied, since
they reduce to trivial "cat"...
--
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: 5043 bytes --]
#Stacked git bash completion.
#TODO:
# My opinion about bash completion is that they're excessively slow, especially
# when the system is under load.
#
# So:
# - save the list of stg commands in a file, created at install moment; on an
# idle Athlon 64 laptop at 800MHz, stg help takes 0.22 seconds of CPU time,
# without disk I/O.
#
# - read .git/patches/$branch/{applied,unapplied} directly instead of invoking
# stg.
#
#XXX: must test for bash version, done in generic bash-completion and the
#generic value can be seen from here, if we are included by the loop at the end
#of /etc/bash_completion, i.e. if we're installed in /etc/bash-completion.d.
#
#Gentoo should be fixed to allow this.
bashdefault="-o bashdefault"
default="-o default"
#XXX: not StGit specific, valid for git too.
__git_refs()
{
for i in $(echo .git/refs/heads/*); do
echo ${i#.git/refs/heads/}
done
for i in $(echo .git/refs/tags/*); do
echo ${i#.git/refs/tags/}
done
echo HEAD
}
__stg_unapplied()
{
stg unapplied 2>/dev/null $@
}
__stg_applied()
{
stg applied 2>/dev/null $@
}
__stg_all_patches()
{
__stg_applied $@; __stg_unapplied $@
}
#XXX: Find a better name for this.
#
__stg_all_patch_ranges()
{
__stg_all_patches $@|while read i; do echo $i/; done
}
__stg_top()
{
stg top 2>/dev/null $@
}
__stg_branches()
{
#for i in $(compgen -f .git/patches/); do
for i in $(echo .git/patches/*); do
echo ${i#.git/patches/}
done
}
_stg ()
{
local cur cmd cmds opts
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]}
local o_help="-h --help"
local o_branch="-b --branch"
#XXX: Add -b support - pass "-b branch" to unapplied and applied.
#This can be done by calling __stg_unapplied directly below
#instead of setting patches here.
#But: how to look for -b? I'm scared about looping over opts
#(I don't like completions when they take so much time).
case $cmd in
push)
if [ "$prev" = "-t" -o "$prev" = "--to" ]; then
if [ "${cur#*:}" != "${cur}" ]; then
# Complete the 2nd range component, after ':'.
COMPREPLY=( $(compgen -W "$(__stg_unapplied)" -- ${cur#*:}) )
else
COMPREPLY=( $(compgen -W "$(__stg_unapplied)" -- $cur) )
fi
else
opts="-a --all -n --number -t --to --reverse --undo $o_help"
COMPREPLY=( $(compgen -W "${opts} $(__stg_unapplied)" -- $cur) )
fi
;;
pop)
if [ "$prev" = "-t" -o "$prev" = "--to" ]; then
COMPREPLY=( $(compgen -W "$(__stg_applied)" -- $cur) )
else
opts="-a --all -n --number -t --to $o_help"
COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
fi
;;
mail)
if [ "$prev" = "-r" -o "$prev" = "--range" ]; then
if [ "${cur#*:}" != "${cur}" ]; then
COMPREPLY=( $(compgen -W "$(__stg_applied)" -- ${cur#*:}) )
else
COMPREPLY=( $(compgen -W "$(__stg_applied)" -- $cur) )
fi
else
opts="-a --all -r --range --to --cc --bcc -v --version \
-t --template -f --first -s --sleep --refid -u --smtp-user \
-p --smtp-password $o_branch $o_help"
COMPREPLY=( $(compgen $bashdefault -W "${opts} \
$(__stg_applied)" -- $cur) )
fi
;;
diff)
if [ "$prev" = "-r" ]; then
if [ "${cur#*:}" != "${cur}" ]; then
COMPREPLY=( $(compgen -W "$(__stg_all_patch_ranges)" -- \
${cur#*:}) )
else
COMPREPLY=( $(compgen -W "$(__stg_all_patch_ranges)" -- \
$cur) )
fi
else
opts="-r -s --stat $o_help"
COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
fi
;;
id)
if [ "$prev" = "-b" -o "$prev" = "--branch" ]; then
COMPREPLY=( $(compgen -W "$(__stg_branches)" -- $cur) )
else
opts="$o_branch $o_help"
#there's a lot of possible id's to complete
COMPREPLY=( $(compgen -W "${opts} $(__stg_all_patch_ranges) \
$(__git_refs)" -- $cur) )
fi
;;
rename)
if [ "$prev" = "-b" -o "$prev" = "--branch" ]; then
COMPREPLY=( $(compgen -W "$(__stg_branches)" -- $cur) )
else
COMPREPLY=( $(compgen -W "$(__stg_all_patches)" -- $cur) )
fi
;;
delete)
opts="${o_help}"
COMPREPLY=( $(compgen -W "${opts} $(__stg_unapplied; __stg_top)" \
-- $cur) )
;;
series|unapplied|applied)
if [ "$prev" = "-b" -o "$prev" = "--branch" ]; then
COMPREPLY=( $(compgen -W "$(__stg_branches)" -- $cur) )
else
opts="$o_branch $o_help"
[ "$cmd" = "series" ] && \
opts="$opts -e --empty"
COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
fi
;;
refresh)
opts="-f --force -e --edit -s --showpatch -m --message \
-a --author --authname --authemail --authdate --commname
--commemail $o_help"
COMPREPLY=( $(compgen $bashdefault -W "${opts}" -- $cur) )
;;
*)
COMPREPLY=( $(compgen $bashdefault -W "${o_help}" -f -- $cur) )
;;
esac
fi
}
complete $default -F _stg stg
# vi: set ft=sh sw=4:
^ 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).