* Adding Text to Each Match
@ 2005-12-12 15:39 Chris Johnson
2005-12-12 16:21 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Chris Johnson @ 2005-12-12 15:39 UTC (permalink / raw)
To: zsh-users
Is there a non-loop way to replicate text for each filename matching a
pattern? For example, I'm trying to generate e-mail messages with
attachments that match a pattern to send with mutt. Each attachment
needs to be specified with the -a option.
echo body | mutt -a file1_foo -a file2_foo \
-s "Here's your foo" username
Is there something in zsh that would let me say
echo body | mutt [prefix all matches to *foo with -a] \
-s "Here's your foo" username
that would expand to the command listed above?
I think there's been some talk of this, but I don't know what to search
for in the archives. Thanks for your help!
--
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding Text to Each Match
2005-12-12 15:39 Adding Text to Each Match Chris Johnson
@ 2005-12-12 16:21 ` Bart Schaefer
2005-12-12 18:56 ` Peter Stephenson
2005-12-12 19:02 ` Chris Johnson
0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2005-12-12 16:21 UTC (permalink / raw)
To: Chris Johnson, zsh-users
On Dec 12, 10:39am, Chris Johnson wrote:
}
} Is there a non-loop way to replicate text for each filename matching a
} pattern? [...]
} I think there's been some talk of this, but I don't know what to search
} for in the archives.
Try searching for "mutt". The thread is "globbing with interposition"
from back in April, and the short-and-sweet answer is that mutt doesn't
care whether there's a space between the -a and the file name, so you
can run them together as -afile1 -afile2 etc., which means you can use
brace expansion. See zsh-users/8707.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding Text to Each Match
2005-12-12 16:21 ` Bart Schaefer
@ 2005-12-12 18:56 ` Peter Stephenson
2005-12-15 4:39 ` Bart Schaefer
2005-12-12 19:02 ` Chris Johnson
1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2005-12-12 18:56 UTC (permalink / raw)
To: zsh-users
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Try searching for "mutt". The thread is "globbing with interposition"
> from back in April, and the short-and-sweet answer is that mutt doesn't
> care whether there's a space between the -a and the file name, so you
> can run them together as -afile1 -afile2 etc., which means you can use
> brace expansion. See zsh-users/8707.
Do we still want to have a glob qualifer to specify no reordering?
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.58
diff -u -r1.58 expn.yo
--- Doc/Zsh/expn.yo 4 Nov 2005 16:20:34 -0000 1.58
+++ Doc/Zsh/expn.yo 12 Dec 2005 18:54:30 -0000
@@ -1958,11 +1958,13 @@
inode change respectively; if tt(d), files in subdirectories appear before
those in the current directory at each level of the search DASH()- this is best
combined with other criteria, for example `tt(odon)' to sort on names for
-files within the same directory. Note that tt(a), tt(m), and tt(c) compare
+files within the same directory; if tt(N), no sorting is performed.
+Note that tt(a), tt(m), and tt(c) compare
the age against the current time, hence the first name in the list is the
youngest file. Also note that the modifiers tt(^) and tt(-) are used,
so `tt(*(^-oL))' gives a list of all files sorted by file size in descending
-order, following any symbolic links.
+order, following any symbolic links. Unless tt(oN) is used, multiple order
+specifiers may occur to resolve ties.
)
item(tt(O)var(c))(
like `tt(o)', but sorts in descending order; i.e. `tt(*(^oc))' is the
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.48
diff -u -r1.48 glob.c
--- Src/glob.c 13 Oct 2005 16:30:14 -0000 1.48
+++ Src/glob.c 12 Dec 2005 18:54:31 -0000
@@ -56,11 +56,14 @@
#define GS_NAME 1
#define GS_DEPTH 2
-#define GS_SIZE 4
-#define GS_ATIME 8
-#define GS_MTIME 16
-#define GS_CTIME 32
-#define GS_LINKS 64
+
+#define GS_SHIFT_BASE 4
+
+#define GS_SIZE (GS_SHIFT_BASE)
+#define GS_ATIME (GS_SHIFT_BASE << 1)
+#define GS_MTIME (GS_SHIFT_BASE << 2)
+#define GS_CTIME (GS_SHIFT_BASE << 3)
+#define GS_LINKS (GS_SHIFT_BASE << 4)
#define GS_SHIFT 5
#define GS__SIZE (GS_SIZE << GS_SHIFT)
@@ -69,7 +72,8 @@
#define GS__CTIME (GS_CTIME << GS_SHIFT)
#define GS__LINKS (GS_LINKS << GS_SHIFT)
-#define GS_DESC 4096
+#define GS_DESC (GS_SHIFT_BASE << (2*GS_SHIFT))
+#define GS_NONE (GS_SHIFT_BASE << (2*GS_SHIFT+1))
#define GS_NORMAL (GS_SIZE | GS_ATIME | GS_MTIME | GS_CTIME | GS_LINKS)
#define GS_LINKED (GS_NORMAL << GS_SHIFT)
@@ -1414,6 +1418,7 @@
case 'm': t = GS_MTIME; break;
case 'c': t = GS_CTIME; break;
case 'd': t = GS_DEPTH; break;
+ case 'N': t = GS_NONE; break;
default:
zerr("unknown sort specifier", NULL, 0);
restore_globstate(saved);
@@ -1622,10 +1627,13 @@
matchct = 1;
}
}
- /* Sort arguments in to lexical (and possibly numeric) order. *
- * This is reversed to facilitate insertion into the list. */
- qsort((void *) & matchbuf[0], matchct, sizeof(struct gmatch),
- (int (*) _((const void *, const void *)))gmatchcmp);
+
+ if (!(gf_sortlist[0] & GS_NONE)) {
+ /* Sort arguments in to lexical (and possibly numeric) order. *
+ * This is reversed to facilitate insertion into the list. */
+ qsort((void *) & matchbuf[0], matchct, sizeof(struct gmatch),
+ (int (*) _((const void *, const void *)))gmatchcmp);
+ }
if (first < 0) {
first += matchct;
@@ -1637,10 +1645,21 @@
else if (end > matchct)
end = matchct;
if ((end -= first) > 0) {
- matchptr = matchbuf + matchct - first - end;
- while (end-- > 0) { /* insert matches in the arg list */
- insertlinknode(list, node, matchptr->name);
- matchptr++;
+ if (gf_sortlist[0] & GS_NONE) {
+ /* Match list was never reversed, so insert back to front. */
+ matchptr = matchbuf + matchct - first - 1;
+ while (end-- > 0) {
+ /* insert matches in the arg list */
+ insertlinknode(list, node, matchptr->name);
+ matchptr--;
+ }
+ } else {
+ matchptr = matchbuf + matchct - first - end;
+ while (end-- > 0) {
+ /* insert matches in the arg list */
+ insertlinknode(list, node, matchptr->name);
+ matchptr++;
+ }
}
}
free(matchbuf);
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding Text to Each Match
2005-12-12 16:21 ` Bart Schaefer
2005-12-12 18:56 ` Peter Stephenson
@ 2005-12-12 19:02 ` Chris Johnson
1 sibling, 0 replies; 5+ messages in thread
From: Chris Johnson @ 2005-12-12 19:02 UTC (permalink / raw)
To: zsh-users; +Cc: Bart Schaefer
Bart Schaefer sent me the following 0.5K:
> On Dec 12, 10:39am, Chris Johnson wrote:
>
> } Is there a non-loop way to replicate text for each filename matching a
> } pattern? [...]
> } I think there's been some talk of this, but I don't know what to search
> } for in the archives.
>
> Try searching for "mutt". The thread is "globbing with interposition"
> from back in April, and the short-and-sweet answer is that mutt doesn't
> care whether there's a space between the -a and the file name, so you
> can run them together as -afile1 -afile2 etc., which means you can use
> brace expansion. See zsh-users/8707.
Got it. Thanks!
--
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding Text to Each Match
2005-12-12 18:56 ` Peter Stephenson
@ 2005-12-15 4:39 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2005-12-15 4:39 UTC (permalink / raw)
To: zsh-users
On Dec 12, 6:56pm, Peter Stephenson wrote:
}
} Do we still want to have a glob qualifer to specify no reordering?
I think it's useful, or at least not useless.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-12-15 4:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-12 15:39 Adding Text to Each Match Chris Johnson
2005-12-12 16:21 ` Bart Schaefer
2005-12-12 18:56 ` Peter Stephenson
2005-12-15 4:39 ` Bart Schaefer
2005-12-12 19:02 ` Chris Johnson
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).