zsh-workers
 help / color / mirror / code / Atom feed
* du(1) completion and a little $RANDOM problem
@ 2003-07-16 11:16 Guillaume Chazarain
  2003-07-16 11:30 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Guillaume Chazarain @ 2003-07-16 11:16 UTC (permalink / raw)
  To: zsh-workers

Hi list,

Zsh's default completion on the du(1) command is to show only the
directories, but why? since du can also be used on files.

Here is what I mean, against zsh-4.1.1.

--- Completion/Unix/Type/_directories.old
+++ Completion/Unix/Type/_directories
@@ -1,4 +1,4 @@
-#compdef rmdir df du dircmp -P -value-,*path,-default-
+#compdef rmdir df dircmp -P -value-,*path,-default-
 
 local expl
 

Another problem I have deals with $RANDOM. Using echo $RANDOM works as
expected, a new random value is printed each time.

[g ~]$ echo $RANDOM
29407
[g ~]$ echo $RANDOM
31292
[g ~]$ echo $RANDOM
11843
[g ~]$ echo $RANDOM
22883
[g ~]$ echo $RANDOM
20814

But if I do echo `echo $RANDOM` then the random value is always the same.

[g ~]$ echo `echo $RANDOM`
6853
[g ~]$ echo `echo $RANDOM`
6853
[g ~]$ echo `echo $RANDOM`
6853
[g ~]$ echo `echo $RANDOM`
6853
[g ~]$ echo `echo $RANDOM`
6853


And the behaviour is the same if zsh is called as sh.

Thanks
Guillaume







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

* Re: du(1) completion and a little $RANDOM problem
  2003-07-16 11:16 du(1) completion and a little $RANDOM problem Guillaume Chazarain
@ 2003-07-16 11:30 ` Peter Stephenson
  2003-07-16 11:46   ` Bart Schaefer
  2003-08-20 10:35   ` PATCH: " Oliver Kiddle
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 2003-07-16 11:30 UTC (permalink / raw)
  To: zsh-workers

Guillaume Chazarain wrote:
> Hi list,
> 
> Zsh's default completion on the du(1) command is to show only the
> directories, but why? since du can also be used on files.

It probably deserves it's own completion.  Note if you have GNU du you
can:

compdef _gnu_generic du

for best results.  (I wonder if we could autodetect or at least guess
some of these at startup where guessing wrong isn't too painful?)

> But if I do echo `echo $RANDOM` then the random value is always the same.

This is documented in the manual entry.

     RANDOM <S>
          A pseudo-random integer from 0  to  32767,  newly  gen-
          erated  each  time  this  parameter is referenced.  The
          random number generator can be seeded  by  assigning  a
          numeric value to RANDOM.

          The values of RANDOM form  an  intentionally-repeatable
          pseudo-random sequence; subshells that reference RANDOM
          will result in identical  pseudo-random  values  unless
          the  value  of  RANDOM  is  referenced or seeded in the
          parent shell in between subshell invocations.

The workaround is to refer to it in the current shell between
invocations.  The only other fix would be some communication with the
subshell.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: du(1) completion and a little $RANDOM problem
  2003-07-16 11:30 ` Peter Stephenson
@ 2003-07-16 11:46   ` Bart Schaefer
  2003-07-16 12:09     ` Sven Wischnowsky
  2003-07-17 10:17     ` Oliver Kiddle
  2003-08-20 10:35   ` PATCH: " Oliver Kiddle
  1 sibling, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2003-07-16 11:46 UTC (permalink / raw)
  To: zsh-workers

On Jul 16, 12:30pm, Peter Stephenson wrote:
} Subject: Re: du(1) completion and a little $RANDOM problem
}
} compdef _gnu_generic du
} 
} for best results.  (I wonder if we could autodetect or at least guess
} some of these at startup where guessing wrong isn't too painful?)

Sven, Oliver and I have had several threads about this dating back a
very long time -- see for example zsh-workers/10998.

(Does anyone know what's happened to Sven, by the way?)


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

* Re: du(1) completion and a little $RANDOM problem
  2003-07-16 11:46   ` Bart Schaefer
@ 2003-07-16 12:09     ` Sven Wischnowsky
  2003-07-17 10:17     ` Oliver Kiddle
  1 sibling, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 2003-07-16 12:09 UTC (permalink / raw)
  To: zsh-workers


Hi folks!

Bart Schaefer wrote:

> (Does anyone know what's happened to Sven, by the way?)

Yes. He's been *very* busy at his new job -- and only cursory lurking
in this list. Sorry. I should probably try to improve my life's
quality by directing more of my attention to things zsh again...


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@berkom.de


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

* Re: du(1) completion and a little $RANDOM problem
  2003-07-16 11:46   ` Bart Schaefer
  2003-07-16 12:09     ` Sven Wischnowsky
@ 2003-07-17 10:17     ` Oliver Kiddle
  1 sibling, 0 replies; 8+ messages in thread
From: Oliver Kiddle @ 2003-07-17 10:17 UTC (permalink / raw)
  To: zsh-workers

Bart wrote:
> On Jul 16, 12:30pm, Peter Stephenson wrote:
> } 
> } for best results.  (I wonder if we could autodetect or at least guess
> } some of these at startup where guessing wrong isn't too painful?)
> 
> Sven, Oliver and I have had several threads about this dating back a
> very long time -- see for example zsh-workers/10998.

That discussion resulted in _pick_variant. You need to be fairly
confident that running the command in question to see what it is is
safe and quick though.

I'd have thought it would be safe for du as it doesn't have any
destructive modes of operation that I'm aware of. On Solaris 8, du
--version produces:

  du: illegal option -- -
  usage: du [-a][-d][-k][-r][-o|-s][-L] [file ...]

I don't have access to any other systems to see what they do. The trick
used by _finger to see what options are available is quite nice.
Otherwise the best way to determine what options are available tends to
be a big case statement checking $OSTYPE (after using _pick_variant to
check for GNU).

Oliver

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________


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

* PATCH: Re: du(1) completion and a little $RANDOM problem
  2003-07-16 11:30 ` Peter Stephenson
  2003-07-16 11:46   ` Bart Schaefer
@ 2003-08-20 10:35   ` Oliver Kiddle
  2003-08-20 14:22     ` Doug Kearns
  1 sibling, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2003-08-20 10:35 UTC (permalink / raw)
  To: zsh-workers

On 16 Jul, Peter wrote:
> Guillaume Chazarain wrote:
> > Hi list,
> > 
> > Zsh's default completion on the du(1) command is to show only the
> > directories, but why? since du can also be used on files.
> 
> It probably deserves it's own completion.  Note if you have GNU du you
> can:
> 
> compdef _gnu_generic du
> 
> for best results.  (I wonder if we could autodetect or at least guess
> some of these at startup where guessing wrong isn't too painful?)

Well here's a completion function for du then. We perhaps should have
completions for all the really standard UNIX stuff that GNU packages as
`coreutils'. Trouble is that these are just the sort of things that have
slightly different options on every system you look at.

Oliver

#compdef du

if _pick_variant gnu=Free\ Soft unix --version; then
  _arguments -s \
    '(-a --all -s --summarize)'{-a,--all}'[write counts for all files]' \
    '--apparent-size[print apparent sizes rather than disc usage]' \
    '(-B --block-size -k)'{-B,--block-size=}'[specify block size]:size (bytes)' \
    '(-B --block-size -k --apparent-size -b --bytes)'{-b,--bytes}'[equivalent to --apparent-size --block-size=1]' \
    '(-c --total)'{-c,--total}'[produce a grand total]' \
    '(-D --dereference-args -L --dereference)'{-D,--dereference-args}'[dereference arguments that are symlinks]' \
    '(-h --human-readable -H --si)'{-h,--human-readable}'[print sizes in human readable format]' \
    '(-H --si -h --human-readable)'{-H,--si}'[human readable form using powers of 1000]' \
    '(-B --block-size)-k[use block size of 1k]' \
    '(-l --count-links)'{-l,--count-links}'[count sizes many times if hard linked]' \
    '(-L --dereference -D --dereference-args)'{-L,--dereference}'[dereference all symlinks]' \
    '(-S --separate-dirs)'{-S,--seperate-dirs}'[do not include size of subdirectories]' \
    '(-s --summarize --max-depth -a --all)'{-s,--summarize}'[only display total for each argument]' \
    '(-x --one-file-system)'{-x,--one-file-system}'[skip directories on different filesystems]' \
    \*{-X+,--exclude-from=}'[exclude files matching any pattern in file]:file:_files' \
    '*--exclude=[exclude files matching pattern]:pattern' \
    '(-s --summarize)--max-depth=[maximum levels to recurse]:levels' \
    '(* -)--help[display help information]' \
    '(* -)--version[display version information]' \
    '*:file:_files'
  return
else
  # based on $OSTYPE = solaris2.8
  local xdev='[skip directories on different filesystems]'
  if [[ ${commands[$words[1]]:-$words[1]} = *xpg4* ]]; then
    args=( -x$xdev )
  else
    args=( -d$xdev
      '-L[dereference symlinks]'
      "(-a)-o[do not add child directories' usage to parent's total]"
    )
  fi
  _arguments -s "$args[@]" \
    '(-s -o)-a[write counts for all files]' \
    '-k[use block size of 1k]' \
    '-r[notify about unreadable files/directories]' \
    '(-a)-s[only display total for each argument]' \
    '*:file:_files'
  return
fi


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

* Re: PATCH: Re: du(1) completion and a little $RANDOM problem
  2003-08-20 10:35   ` PATCH: " Oliver Kiddle
@ 2003-08-20 14:22     ` Doug Kearns
  2003-08-21 12:35       ` Oliver Kiddle
  0 siblings, 1 reply; 8+ messages in thread
From: Doug Kearns @ 2003-08-20 14:22 UTC (permalink / raw)
  To: zsh-workers

On Wed, Aug 20, 2003 at 12:35:44PM +0200, Oliver Kiddle wrote:

<snip>
 
> Well here's a completion function for du then. We perhaps should have
> completions for all the really standard UNIX stuff that GNU packages as
> `coreutils'.

Yes, this would be nice and it's on my todo list along with support for
all the 'standard' environment variables, but ...

> Trouble is that these are just the sort of things that have
> slightly different options on every system you look at.

exactly ... [sigh]

Regards,
Doug


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

* Re: PATCH: Re: du(1) completion and a little $RANDOM problem
  2003-08-20 14:22     ` Doug Kearns
@ 2003-08-21 12:35       ` Oliver Kiddle
  0 siblings, 0 replies; 8+ messages in thread
From: Oliver Kiddle @ 2003-08-21 12:35 UTC (permalink / raw)
  To: zsh-workers

Doug Kearns wrote:

> Yes, this would be nice and it's on my todo list along with support for
> all the 'standard' environment variables, but ...

I didn't think we were that lacking in terms of standard environment
variables. There's a number that could be handled by _command_names
(EDITOR, VISUAL, CC etc) perhaps. All *path, *PATH and LC_* variables
are handled by a pattern completion.

> > Trouble is that these are just the sort of things that have
> > slightly different options on every system you look at.
> 
> exactly ... [sigh]

Though it's probably better to write them and hopefully over time they
can handle more systems.

Oliver


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

end of thread, other threads:[~2003-08-21 12:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-16 11:16 du(1) completion and a little $RANDOM problem Guillaume Chazarain
2003-07-16 11:30 ` Peter Stephenson
2003-07-16 11:46   ` Bart Schaefer
2003-07-16 12:09     ` Sven Wischnowsky
2003-07-17 10:17     ` Oliver Kiddle
2003-08-20 10:35   ` PATCH: " Oliver Kiddle
2003-08-20 14:22     ` Doug Kearns
2003-08-21 12:35       ` Oliver Kiddle

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