* todo.sh completion
@ 2010-11-25 13:23 Julien Nicoulaud
2010-11-25 13:45 ` Peter Stephenson
0 siblings, 1 reply; 6+ messages in thread
From: Julien Nicoulaud @ 2010-11-25 13:23 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 137 bytes --]
Hi all,
anyone using todo.sh completion script here ?
I'm using zsh 4.3.10 on Ubuntu 10.10, and does not seem to work.
Regards,
Julien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: todo.sh completion
2010-11-25 13:23 todo.sh completion Julien Nicoulaud
@ 2010-11-25 13:45 ` Peter Stephenson
2010-11-25 13:55 ` Frank Terbeck
0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2010-11-25 13:45 UTC (permalink / raw)
Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
On Thu, 25 Nov 2010 14:23:35 +0100
Julien Nicoulaud <julien.nicoulaud@gmail.com> wrote:
> anyone using todo.sh completion script here ?
>
> I'm using zsh 4.3.10 on Ubuntu 10.10, and does not seem to work.
It's changed since then; try the latest.
pws
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
[-- Attachment #2: _todo.sh --]
[-- Type: text/plain, Size: 4169 bytes --]
#compdef todo.sh
# See http://todotxt.com for todo.sh.
#
# Featurettes:
# - "replace" will complete the original text for editing
# - completing priorities will cycle through A to Z (even without
# menu completion)
# - list and listall will complete +<project> and @<where> from
# values in existing entries
# - will complete after + and @ if typed in message text
setopt localoptions braceccl
local expl curcontext="$curcontext" state line pri nextstate item
local -a cmdlist itemlist match mbegin mend
integer NORMARG
_arguments -s -n : \
'-d[alternate config file]:config file:_files' \
'-f[force, no confirmation]' \
'-h[display help]' \
'-p[plain mode, no colours]' \
'-v[verbose mode, confirmation messages]' \
'-V[display version etc.]' \
'1:command:->commands' \
'*:arguments:->arguments' && return 0
local projmsg="context or project"
local txtmsg="text with contexts or projects"
# Skip "command" as command prefix if words after
if [[ $words[NORMARG] == command && NORMARG -lt CURRENT ]]; then
(( NORMARG++ ))
fi
case $state in
(commands)
cmdlist=(
"add:add TODO ITEM to todo.txt."
"addm:add TODO ITEMs, one per line, to todo.txt."
"addto:add text to file (not item)"
"append:adds to item on line NUMBER the text TEXT."
"archive:moves done items from todo.txt to done.txt."
"command:run internal commands only"
"del:deletes the item on line NUMBER in todo.txt."
"depri:remove prioritization from item"
"do:marks item on line NUMBER as done in todo.txt."
"help:display help"
"list:displays all todo items containing TERM(s), sorted by priority."
"listall:displays items including done ones containing TERM(s)"
"listcon:list all contexts"
"listfile:display all files in .todo directory"
"listpri:displays all items prioritized at PRIORITY."
"move:move item between files"
"prepend:adds to the beginning of the item on line NUMBER text TEXT."
"pri:adds or replace in NUMBER the priority PRIORITY (upper case letter)."
"replace:replace in NUMBER the TEXT."
"remdup:remove exact duplicates from todo.txt."
"report:adds the number of open and done items to report.txt."
)
_describe -t todo-commands 'todo.sh command' cmdlist
;;
(arguments)
case $words[NORMARG] in
(append|command|del|move|mv|prepend|pri|replace|rm)
if (( NORMARG == CURRENT - 1 )); then
nextstate=item
else
case $words[NORMARG] in
(pri)
nextstate=pri
;;
(append|prepend)
nextstate=proj
;;
(move|mv)
nextstate=file
;;
(replace)
item=${words[CURRENT-1]##0##}
compadd -Q -- "${(qq)$(todo.sh -p list "^[ 0]*$item " | sed '/^--/,$d')##<-> (\([A-Z]\) |)}"
;;
esac
fi
;;
(depri|do|dp)
nextstate=item
;;
(a|add|addm|list|ls|listall|lsa)
nextstate=proj
;;
(addto)
if (( NORMARG == CURRENT - 1 )); then
nextstate=file
else
nexstate=proj
fi
;;
(listfile|lf)
if (( NORMARG == CURRENT -1 )); then
nextstate=file
else
_message "Term to search file for"
fi
;;
(listpri|lsp)
nextstate=pri
;;
(*)
return 1
;;
esac
;;
esac
case $nextstate in
(file)
_path_files -W ~/.todo
;;
(item)
itemlist=(${${(M)${(f)"$(todo.sh -p list | sed '/^--/,$d')"}##<-> *}/(#b)(<->) (*)/${match[1]}:${match[2]}})
_describe -t todo-items 'todo item' itemlist
;;
(pri)
if [[ $words[CURRENT] = (|[A-Z]) ]]; then
if [[ $words[CURRENT] = (|Z) ]]; then
pri=A
else
# cycle priority
pri=$words[CURRENT]
pri=${(#)$(( #pri + 1 ))}
fi
_wanted priority expl 'priority' compadd -U -S '' -- $pri
else
_wanted priority expl 'priority' compadd {A-Z}
fi
;;
(proj)
# This completes stuff beginning with + (projects) or @ (contexts);
# these are todo.sh conventions.
if [[ ! -prefix + && ! -prefix @ ]]; then
projmsg=$txtmsg
fi
# In case there are quotes, ignore anything up to whitespace before
# the + or @ (which may not even be there yet).
compset -P '*[[:space:]]'
_wanted search expl $projmsg \
compadd $(todo.sh lsprj) $(todo.sh lsc)
;;
esac
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: todo.sh completion
2010-11-25 13:45 ` Peter Stephenson
@ 2010-11-25 13:55 ` Frank Terbeck
2010-11-25 14:34 ` Julien Nicoulaud
0 siblings, 1 reply; 6+ messages in thread
From: Frank Terbeck @ 2010-11-25 13:55 UTC (permalink / raw)
To: zsh-users
Peter Stephenson wrote:
> Julien Nicoulaud <julien.nicoulaud@gmail.com> wrote:
>> anyone using todo.sh completion script here ?
>>
>> I'm using zsh 4.3.10 on Ubuntu 10.10, and does not seem to work.
>
> It's changed since then; try the latest.
If you're wondering how to use an updated completion function with an
existing installation, here's an example (using the _git completion):
<http://zshwiki.org/home/config/functions>
The procedure is the same for other completions, too.
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: todo.sh completion
2010-11-25 13:55 ` Frank Terbeck
@ 2010-11-25 14:34 ` Julien Nicoulaud
2010-11-25 15:32 ` Peter Stephenson
0 siblings, 1 reply; 6+ messages in thread
From: Julien Nicoulaud @ 2010-11-25 14:34 UTC (permalink / raw)
To: Frank Terbeck; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]
OK, I checked my zshrc and it turns out this was breaking the completion
script:
autoload -U zsh-mime-setup && zsh-mime-setup
I guess this has to do with todo.sh ending with ".sh", since every others
completion scripts work fine. Should I log a bug ?
Julien
2010/11/25 Frank Terbeck <ft@bewatermyfriend.org>
> Peter Stephenson wrote:
> > Julien Nicoulaud <julien.nicoulaud@gmail.com> wrote:
> >> anyone using todo.sh completion script here ?
> >>
> >> I'm using zsh 4.3.10 on Ubuntu 10.10, and does not seem to work.
> >
> > It's changed since then; try the latest.
>
> If you're wondering how to use an updated completion function with an
> existing installation, here's an example (using the _git completion):
>
> <http://zshwiki.org/home/config/functions>
>
> The procedure is the same for other completions, too.
>
> Regards, Frank
>
> --
> In protocol design, perfection has been reached not when there is
> nothing left to add, but when there is nothing left to take away.
> -- RFC 1925
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: todo.sh completion
2010-11-25 14:34 ` Julien Nicoulaud
@ 2010-11-25 15:32 ` Peter Stephenson
2010-11-25 20:26 ` Julien Nicoulaud
0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2010-11-25 15:32 UTC (permalink / raw)
To: zsh-users
On Thu, 25 Nov 2010 15:34:56 +0100
Julien Nicoulaud <julien.nicoulaud@gmail.com> wrote:
> OK, I checked my zshrc and it turns out this was breaking the
> completion script:
>
> autoload -U zsh-mime-setup && zsh-mime-setup
Useful research, thank you.
> I guess this has to do with todo.sh ending with ".sh", since every
> others completion scripts work fine.
Yes, what should happen is that _zsh-mime-handler finds it shouldn't be
handling todo.sh in this case and despatching to normal completion
instead. There were some (at least three) glitches with this. This
fixes the ones I found.
- zsh-mime-handler didn't handle the "-l" option for stuff it passed
through without handling. (This should simply end up with $words
being pruned from the front.)
- _zsh-mime-handler didn't keep empty arguments, which is what
you get when you first try completion on a word.
- _zsh-mime-handler updated $words but didn't update $CURRENT. Best
guess is to keep $CURRENT at the same offset from the end of $words.
Index: Completion/Zsh/Function/_zsh-mime-handler
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Function/_zsh-mime-handler,v
retrieving revision 1.1
diff -p -u -r1.1 _zsh-mime-handler
--- Completion/Zsh/Function/_zsh-mime-handler 23 May 2010 19:54:03 -0000 1.1
+++ Completion/Zsh/Function/_zsh-mime-handler 25 Nov 2010 15:29:27 -0000
@@ -1,9 +1,19 @@
#compdef zsh-mime-handler
+# Given that the handler is likely to change the start of the command
+# line, we'll try to maintain the position from the end of the words
+# array. Hence for example CURRENT gets decremented by one if the
+# handler drops off the start.
+integer end_offset=$(( ${#words} - CURRENT ))
+
# zsh-mime-handler -l is supposed to print out the command line
# with quoting to turn it into a full executable line. So
# we need to use shell splitting to turn it into words and
# then unquoting on those words.
-words=(${(Q)${(z)"$(zsh-mime-handler -l ${words[2,-1]})"}})
+words=(${(z)"$(zsh-mime-handler -l "${(@)words[2,-1]}")"})
+# Careful unquoting: we need to keep a '' as a separate word.
+words=("${(@Q)words}")
+
+(( CURRENT = ${#words} - end_offset ))
_normal
Index: Functions/MIME/zsh-mime-handler
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v
retrieving revision 1.13
diff -p -u -r1.13 zsh-mime-handler
--- Functions/MIME/zsh-mime-handler 8 Aug 2010 17:20:55 -0000 1.13
+++ Functions/MIME/zsh-mime-handler 25 Nov 2010 15:29:27 -0000
@@ -144,7 +144,11 @@ if [[ ! -e $1 ]]; then
fi
done
if [[ -z $nonex_ok ]]; then
- "$@"
+ if (( list )); then
+ print -r -- "${(q)@}"
+ else
+ "$@"
+ fi
return
fi
fi
--
Peter Stephenson <pws@csr.com> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: todo.sh completion
2010-11-25 15:32 ` Peter Stephenson
@ 2010-11-25 20:26 ` Julien Nicoulaud
0 siblings, 0 replies; 6+ messages in thread
From: Julien Nicoulaud @ 2010-11-25 20:26 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 3717 bytes --]
Thank you for the quick answer and fix Peter ! I just built zsh from sources
and it works fine now. By the way, for users who would want to build Zsh
from sources on Ubuntu(/Debian?), I put the steps here:
http://gist.github.com/715855.
Regards,
Julien
2010/11/25 Peter Stephenson <Peter.Stephenson@csr.com>
> On Thu, 25 Nov 2010 15:34:56 +0100
> Julien Nicoulaud <julien.nicoulaud@gmail.com> wrote:
> > OK, I checked my zshrc and it turns out this was breaking the
> > completion script:
> >
> > autoload -U zsh-mime-setup && zsh-mime-setup
>
> Useful research, thank you.
>
> > I guess this has to do with todo.sh ending with ".sh", since every
> > others completion scripts work fine.
>
> Yes, what should happen is that _zsh-mime-handler finds it shouldn't be
> handling todo.sh in this case and despatching to normal completion
> instead. There were some (at least three) glitches with this. This
> fixes the ones I found.
>
> - zsh-mime-handler didn't handle the "-l" option for stuff it passed
> through without handling. (This should simply end up with $words
> being pruned from the front.)
>
> - _zsh-mime-handler didn't keep empty arguments, which is what
> you get when you first try completion on a word.
>
> - _zsh-mime-handler updated $words but didn't update $CURRENT. Best
> guess is to keep $CURRENT at the same offset from the end of $words.
>
> Index: Completion/Zsh/Function/_zsh-mime-handler
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Function/_zsh-mime-handler,v
> retrieving revision 1.1
> diff -p -u -r1.1 _zsh-mime-handler
> --- Completion/Zsh/Function/_zsh-mime-handler 23 May 2010 19:54:03 -0000
> 1.1
> +++ Completion/Zsh/Function/_zsh-mime-handler 25 Nov 2010 15:29:27 -0000
> @@ -1,9 +1,19 @@
> #compdef zsh-mime-handler
>
> +# Given that the handler is likely to change the start of the command
> +# line, we'll try to maintain the position from the end of the words
> +# array. Hence for example CURRENT gets decremented by one if the
> +# handler drops off the start.
> +integer end_offset=$(( ${#words} - CURRENT ))
> +
> # zsh-mime-handler -l is supposed to print out the command line
> # with quoting to turn it into a full executable line. So
> # we need to use shell splitting to turn it into words and
> # then unquoting on those words.
> -words=(${(Q)${(z)"$(zsh-mime-handler -l ${words[2,-1]})"}})
> +words=(${(z)"$(zsh-mime-handler -l "${(@)words[2,-1]}")"})
> +# Careful unquoting: we need to keep a '' as a separate word.
> +words=("${(@Q)words}")
> +
> +(( CURRENT = ${#words} - end_offset ))
>
> _normal
> Index: Functions/MIME/zsh-mime-handler
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v
> retrieving revision 1.13
> diff -p -u -r1.13 zsh-mime-handler
> --- Functions/MIME/zsh-mime-handler 8 Aug 2010 17:20:55 -0000
> 1.13
> +++ Functions/MIME/zsh-mime-handler 25 Nov 2010 15:29:27 -0000
> @@ -144,7 +144,11 @@ if [[ ! -e $1 ]]; then
> fi
> done
> if [[ -z $nonex_ok ]]; then
> - "$@"
> + if (( list )); then
> + print -r -- "${(q)@}"
> + else
> + "$@"
> + fi
> return
> fi
> fi
>
> --
> Peter Stephenson <pws@csr.com> Software Engineer
> Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
> Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ,
> UK
>
>
> Member of the CSR plc group of companies. CSR plc registered in England and
> Wales, registered number 4187346, registered office Churchill House,
> Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-11-25 20:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-25 13:23 todo.sh completion Julien Nicoulaud
2010-11-25 13:45 ` Peter Stephenson
2010-11-25 13:55 ` Frank Terbeck
2010-11-25 14:34 ` Julien Nicoulaud
2010-11-25 15:32 ` Peter Stephenson
2010-11-25 20:26 ` Julien Nicoulaud
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).