From: "Matt Armstrong" <matt+dated+1010258681.d5e28d@lickey.com>
To: zsh-users@sunsite.dk
Subject: I wonder if this can be improved a bit
Date: Mon, 31 Dec 2001 12:24:35 -0700 [thread overview]
Message-ID: <87ellbxkek.fsf@squeaker.lickey.com> (raw)
I'm implementing a completion system for Perforce's
(<URL:http://www.perforce.com)>) p4 command. Like CVS, the p4 command
takes sub-commands (p4 add, p4 submit, etc.).
The p4 command prints out the list of available sub-commands with
"p4 -s help commands". I have this bit of code that'll eventually go
into my _p4 completion system. But I wonder if it can be improved.
# This requires EXTENDED_GLOB to be set
setopt extendedglob
local a
a=( ${(f)"$(p4 -s help commands 2>&1)"} )
a=( ${(M)a:#info: *} )
a=( ${a/(#b)info: #([a-z0-9]##) */$match[1]} )
typeset -A _p4_cmds
_p4_cmds=()
for i in $a; do
_p4_cmds[$a]=""
done
So now _p4_cmds is an associative array of available sub commands.
Here I have annotated questions about this code.
# This requires EXTENDED_GLOB to be set
setopt extendedglob
Can I depend on the completion widgets setting EXTENDED_GLOB for me?
local a
a=( ${(f)"$(p4 -s help commands 2>&1)"} )
I will eventually change this to the more correct
"$(_call_program commands p4 -s help commands) ".
a=( ${(M)a:#info: *} )
^^^
The whitespace there is a space followed by a tab character. Is there
any more readable way to include a tab character? A \t escape sequence?
a=( ${a/(#b)info: #([a-z0-9]##) */$match[1]} )
typeset -A _p4_cmds
for i in $a; do
_p4_cmds[$a]=""
done
Is there a simple way to turn an array (a b c) into (a "" b "" c "")?
Then I could assign _p4_cmds in one statement and dump the loop.
--
matt
next reply other threads:[~2001-12-31 19:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-31 19:24 Matt Armstrong [this message]
2002-01-02 16:24 ` Oliver Kiddle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ellbxkek.fsf@squeaker.lickey.com \
--to=matt+dated+1010258681.d5e28d@lickey.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).