zsh-workers
 help / color / mirror / code / Atom feed
* Re: Globbing feature suggestion
       [not found]   ` <871x0ge5ge.fsf@shazam.localnet>
@ 2005-12-15  4:34     ` Bart Schaefer
  2005-12-15 10:45       ` Peter Stephenson
  2005-12-15 23:59       ` Jonathan Hankins
  0 siblings, 2 replies; 3+ messages in thread
From: Bart Schaefer @ 2005-12-15  4:34 UTC (permalink / raw)
  To: Jonathan Hankins; +Cc: zsh-workers

[zsh-workers copied]

On Dec 13,  9:13pm, Jonathan Hankins wrote:
}
} >  -nogroup is the glob qualifier
} >  (e['stat -s -A reply +gid $REPLY;
} > reply=(${${(M)reply:#<->}/<->/$REPLY})'])
} 
} This doesn't work for me -- stat -s returns '???' when there is no
} pw/grent for the the u/gid.

Urk.  Sorry about that; I don't actually *have* any files with unknown
uid/gid on my system, but I had assumed "stat" would return the numeric
ID in the absence of a name, the way "ls -l" does.

In fact I think it's pretty darn useless to return '???' for all unknown
IDs, as if they were equivalent.  Would anyone seriously object if that
were changed?

} It works if I change it to:
} 
}   -nogroup is the glob qualifier
}   (e['stat -s -A reply +gid $REPLY;
}   reply=(${${(M)reply:#???}/???/$REPLY})'])

As that's written, ??? is a pattern matching any three characters, so if
you have any 3-letter usernames on your system, that would improperly
include them.  You need \?\?\? instead.


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

* Re: Globbing feature suggestion
  2005-12-15  4:34     ` Globbing feature suggestion Bart Schaefer
@ 2005-12-15 10:45       ` Peter Stephenson
  2005-12-15 23:59       ` Jonathan Hankins
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2005-12-15 10:45 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer <schaefer@brasslantern.com> wrote:
> Urk.  Sorry about that; I don't actually *have* any files with unknown
> uid/gid on my system, but I had assumed "stat" would return the numeric
> ID in the absence of a name, the way "ls -l" does.
> 
> In fact I think it's pretty darn useless to return '???' for all unknown
> IDs, as if they were equivalent.  Would anyone seriously object if that
> were changed?

I don't see why not.  I think it was that way because you can get both (with
stat -rs).

Index: Src/Modules/stat.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/stat.c,v
retrieving revision 1.9
diff -u -r1.9 stat.c
--- Src/Modules/stat.c	2 Nov 2005 19:29:53 -0000	1.9
+++ Src/Modules/stat.c	15 Dec 2005 10:42:17 -0000
@@ -140,10 +140,16 @@
 #ifdef HAVE_GETPWUID
 	struct passwd *pwd;
 	pwd = getpwuid(uid);
-	strcat(outbuf, pwd ? pwd->pw_name : "???");
-#else /* !HAVE_GETPWUID */
-	strcat(outbuf, "???");
+	if (pwd)
+	    strcat(outbuf, pwd->pw_name);
+	else
 #endif /* !HAVE_GETPWUID */
+	{
+	    char *optr;
+	    for (optr = outbuf; *optr; optr++)
+		;
+	    sprintf(optr, "%lu", (unsigned long)uid);
+	}
 	if (flags & STF_RAW)
 	    strcat(outbuf, ")");
     }
@@ -163,10 +169,16 @@
 #ifdef HAVE_GETGRGID
 	struct group *gr;
 	gr = getgrgid(gid);
-	strcat(outbuf, gr ? gr->gr_name : "???");
-#else /* !HAVE_GETGRGID */
-	strcat(outbuf, "???");
+	if (gr)
+	    strcat(outbuf, gr->gr_name);
+	else
 #endif /* !HAVE_GETGRGID */
+	{
+	    char *optr;
+	    for (optr = outbuf; *optr; optr++)
+		;
+	    sprintf(optr, "%lu", (unsigned long)gid);
+	}
 	if (flags & STF_RAW)
 	    strcat(outbuf, ")");
     }


-- 
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] 3+ messages in thread

* Re: Globbing feature suggestion
  2005-12-15  4:34     ` Globbing feature suggestion Bart Schaefer
  2005-12-15 10:45       ` Peter Stephenson
@ 2005-12-15 23:59       ` Jonathan Hankins
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Hankins @ 2005-12-15 23:59 UTC (permalink / raw)
  To: zsh-workers

Oops -- meant to follow-up to the list -- still learning my way around
Gnus :-)

Bart Schaefer <schaefer@brasslantern.com> writes:

> [zsh-workers copied]
>
> On Dec 13, 9:13pm, Jonathan Hankins wrote:
> }
> } >  -nogroup is the glob qualifier (e['stat -s -A reply +gid $REPLY;
> } > reply=(${${(M)reply:#<->}/<->/$REPLY})'])
> }  This doesn't work for me -- stat -s returns '???' when there is no
> } pw/grent for the the u/gid.
>
> Urk.  Sorry about that; I don't actually *have* any files with unknown
> uid/gid on my system, but I had assumed "stat" would return the
> numeric ID in the absence of a name, the way "ls -l" does.

I didn't either, but it gave me the chance to discover that chown(1)
on my linux box works if you specify a numeric ID, even if there is no
corresponding pw/grent.  Who would have guessed?

> In fact I think it's pretty darn useless to return '???' for all
> unknown IDs, as if they were equivalent.  Would anyone seriously
> object if that were changed?

I thought the same when I saw it.  I guess it _does_ give you a way to
tell when a user or group does _not_ exist.

> } It works if I change it to:
> } 
> }   -nogroup is the glob qualifier (e['stat -s -A reply +gid $REPLY;
> } reply=(${${(M)reply:#???}/???/$REPLY})'])
>
> As that's written, ??? is a pattern matching any three characters, so
> if you have any 3-letter usernames on your system, that would
> improperly include them.  You need \?\?\? instead.

Yeah, I had the backslashes at first, then I tried without it and it
still matched, so my brain shut off for a minute and I forgot that
(e::) re-evaluates its argument.

Speaking of nearly-useless globbing, here is a function to glob all
files that are group-owned by _any_ of your groups, including primary
(login) GID.  Contrast with (G):

--
# $Id: is_gid_file,v 1.3 2005/12/14 00:21:38 jhankins Exp $

# Compare gid of file specified in $REPLY to all of user's groups.  Use like:
#
#   % print *(+cmp_gid)
#
# to list all files group-owned by _any_ of user's groups.  Compare to:
#
#   % print *(G)
#
# which only lists files owned by user's primary group.
#

emulate -L zsh
zmodload -i zsh/stat

typeset -ag _gids

if [[ $#_gids < 1 ]]; then
    _gids=($(id -G))
fi

[[ -n ${(M)_gids:#$(stat +gid -- $REPLY)} ]]

--

Thanks,

-Jonathan Hankins

-- 
+------------------+-----------------------------------------------------+
|Jonathan Hankins  | 		       	 jonathan-hankins@mindspring.com |
+------------------+-----------------------------------------------------+


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

end of thread, other threads:[~2005-12-16  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87irtt4uno.fsf@shazam.localnet>
     [not found] ` <1051213041649.ZM21953@candle.brasslantern.com>
     [not found]   ` <871x0ge5ge.fsf@shazam.localnet>
2005-12-15  4:34     ` Globbing feature suggestion Bart Schaefer
2005-12-15 10:45       ` Peter Stephenson
2005-12-15 23:59       ` Jonathan Hankins

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).