zsh-workers
 help / color / mirror / code / Atom feed
* example startup file
@ 2001-05-08 17:58 Oliver Kiddle
  2001-05-08 18:17 ` Zefram
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Oliver Kiddle @ 2001-05-08 17:58 UTC (permalink / raw)
  To: zsh-workers

This is a suggestion for the example zshrc in StartupFiles. I think we
should be encouraging the use of new style completion so the main
change here is to enable it. All deleted compctls have equivalent or
similiar examples in compctl-examples.

I think I've managed to put together a reasonably varied selection of
mostly simple zstyles including one zstyle -e example.

I've not commited this yet to allow for any objections.

Also, I'm not too happy with the autoload for loop: if it finds no
executable files in a directory it emits an error and returns. Does
anyone have any better suggestions which keep things simple. As I see
it, you either also loop for files or use the N nullglob flag and
redirect outout because autoload with no arguments outputs all
functions.

I get directories in fpath duplicated with this .zshrc after compinit
which isn't too good. Maybe typeset -U fpath should be the default?

Etc/FEATURES could also do with an update before 4.0.1. At the very
least to update the count of options, builtins etc. I'm a bit concerned
about the line which says:
	directory stack access with =num
Either this is wrong, has been broken or I'm misunderstanding it.

Oliver

--- /home/kiddleo/cvs/zsh/StartupFiles/zshrc	Mon Mar 26 00:41:02 2001
+++ zshrc	Tue May  8 18:42:07 2001
@@ -1,5 +1,5 @@
 #
-# Generic .zshrc file for zsh 2.7
+# Example .zshrc file for zsh 4.0
 #
 # .zshrc is sourced in interactive shells.  It
 # should contain commands to set up aliases, functions,
@@ -42,19 +42,19 @@
 
 # Shell functions
 setenv() { export $1=$2 }  # csh compatibility
+freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
 
 # Where to look for autoloaded function definitions
-fpath=(~/.zfunc)
+fpath=($fpath ~/.zfunc)
 
 # Autoload all shell functions from all directories
 # in $fpath that have the executable bit on
 # (the executable bit is not necessary, but gives
 # you an easy way to stop the autoloading of a
 # particular shell function).
-for dirname in $fpath
-do
-  autoload $dirname/*(.x:t)
-done
+#for dirname in $fpath; do
+#  autoload $dirname/*(.x:t)
+#done
 
 # Global aliases -- These do not have to be
 # at the beginning of the command line.
@@ -65,10 +65,7 @@
 manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man)
 export MANPATH
 
-# Filename suffixes to ignore during completion
-fignore=(.o .c~ .old .pro)
-
-# Hosts to use for completion
+# Hosts to use for completion (see later zstyle)
 hosts=(`hostname` ftp.math.gatech.edu prep.ai.mit.edu wuarchive.wustl.edu)
 
 # Set prompts
@@ -85,7 +82,7 @@
 DIRSTACKSIZE=20
 
 # Watch for my friends
-#watch=($(cat ~/.friends))      # watch for people in .friends file
+#watch=( $(<~/.friends) )       # watch for people in .friends file
 watch=(notme)                   # watch for everybody but me
 LOGCHECK=300                    # check every 5 min for login/logout activity
 WATCHFMT='%n %a %l from %m at %t.'
@@ -97,28 +94,62 @@
 setopt   autopushd pushdminus extendedglob rcquotes mailwarning
 unsetopt bgnice autoparamslash
 
-# Setup some basic programmable completions.  To see more examples
-# of these, check Misc/compctl-examples in the zsh distribution.
-compctl -g '*(-/)' cd pushd
-compctl -g '*(/)' rmdir dircmp
-compctl -j -P % -x 's[-] p[1]' -k signals -- kill
-compctl -j -P % fg bg wait jobs disown
-compctl -A shift
-compctl -caF type whence which
-compctl -F unfunction
-compctl -a unalias
-compctl -v unset typeset declare vared readonly export integer
-compctl -e disable
-compctl -d enable
-
 # Some nice key bindings
 #bindkey '^X^Z' universal-argument ' ' magic-space
 #bindkey '^X^A' vi-find-prev-char-skip
+#bindkey '^Xa' _expand_alias
 #bindkey '^Z' accept-and-hold
 #bindkey -s '\M-/' \\\\
 #bindkey -s '\M-=' \|
 
-# bindkey -v             # vi key bindings
+# bindkey -v               # vi key bindings
+
+bindkey -e                 # emacs key bindings
+bindkey ' ' magic-space    # also do history expansion on space
+bindkey '^I' complete-word # complete on tab, leave expansion to _expand
+
+# Setup new style completion system. To see examples of the old style (compctl
+# based) programmable completion, check Misc/compctl-examples in the zsh
+# distribution.
+autoload -U compinit
+compinit
+
+# Completion Styles
+
+# list of completers to use
+zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
+
+# allow one error for every three characters typed in approximate completer
+zstyle -e ':completion:*:approximate:*' max-errors \
+    'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
+    
+# insert all expansions for expand completer
+zstyle ':completion:*:expand:*' tag-order all-expansions
+
+# formatting and messages
+zstyle ':completion:*' verbose yes
+zstyle ':completion:*:descriptions' format '%B%d%b'
+zstyle ':completion:*:messages' format '%d'
+zstyle ':completion:*:warnings' format 'No matches for: %d'
+zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
+zstyle ':completion:*' group-name ''
+
+# match uppercase from lowercase
+zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
+
+# offer indexes before parameters in subscripts
+zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
+
+# command for process lists, the local web server details and host completion
+#zstyle ':completion:*:processes' command 'ps -o pid,s,nice,stime,args'
+#zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html'
+zstyle '*' hosts $hosts
+
+# filename suffixes to ignore during completion (except after rm command)
+zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
+    '*?.old' '*?.pro'
+# the same for old style completion
+#fignore=(.o .c~ .old .pro)
 
-bindkey -e               # emacs key bindings
-bindkey ' ' magic-space  # also do history expansino on space
+# ignore completion functions (until the _ignored completer)
+zstyle ':completion:*:functions' ignored-patterns '_*'

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


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

* Re: example startup file
  2001-05-08 17:58 example startup file Oliver Kiddle
@ 2001-05-08 18:17 ` Zefram
  2001-05-08 19:56 ` Bart Schaefer
  2001-05-09  5:43 ` Andrej Borsenkow
  2 siblings, 0 replies; 8+ messages in thread
From: Zefram @ 2001-05-08 18:17 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

Oliver Kiddle wrote:
>	directory stack access with =num
>Either this is wrong, has been broken or I'm misunderstanding it.

It was changed to ~num some time ago.

-zefram


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

* Re: example startup file
  2001-05-08 17:58 example startup file Oliver Kiddle
  2001-05-08 18:17 ` Zefram
@ 2001-05-08 19:56 ` Bart Schaefer
  2001-05-09 16:46   ` Oliver Kiddle
  2001-05-09  5:43 ` Andrej Borsenkow
  2 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2001-05-08 19:56 UTC (permalink / raw)
  To: Oliver Kiddle, zsh-workers

On May 8,  6:58pm, Oliver Kiddle wrote:
> Subject: example startup file
> 
> I've not commited this yet to allow for any objections.

No objections; comments intermingled below.

> Also, I'm not too happy with the autoload for loop: if it finds no
> executable files in a directory it emits an error and returns. Does
> anyone have any better suggestions which keep things simple. As I see
> it, you either also loop for files or use the N nullglob flag and
> redirect outout because autoload with no arguments outputs all
> functions.

I actually do *both* of those in my .zshrc ...

    autoload $dirname/*(N-.x:t) > /dev/null

(The `-' is to follow symlinks, doesn't seem to be any reason not to.)
However, if you know (as in the example) that fpath is non-empty, you can
just do one loop like this:

    for func in $^fpath/*(N-.x:t); autoload $func

> I get directories in fpath duplicated with this .zshrc after compinit
> which isn't too good. Maybe typeset -U fpath should be the default?

I use:

    typeset -U path cdpath fpath manpath

> --- /home/kiddleo/cvs/zsh/StartupFiles/zshrc	Mon Mar 26 00:41:02 2001
> +++ zshrc	Tue May  8 18:42:07 2001
> @@ -42,19 +42,19 @@
>  
>  # Shell functions
>  setenv() { export $1=$2 }  # csh compatibility

That never was csh-compatible.  This is:

    setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }

> +freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }

I'd throw in a check that the argument actually is a function before calling
unfunction on it.

> +bindkey ' ' magic-space    # also do history expansion on space

That reminds me ... magic-space should magically turn itself off when there
is a !" somewhere to the left of it on the line.  As it is now, !" vanishes
as soon as you type a magic-space, which sort of defeats the purpose.


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

* Re: example startup file
  2001-05-08 17:58 example startup file Oliver Kiddle
  2001-05-08 18:17 ` Zefram
  2001-05-08 19:56 ` Bart Schaefer
@ 2001-05-09  5:43 ` Andrej Borsenkow
  2001-05-09  6:38   ` Dan Nelson
  2 siblings, 1 reply; 8+ messages in thread
From: Andrej Borsenkow @ 2001-05-09  5:43 UTC (permalink / raw)
  To: zsh-workers

On Tue, 8 May 2001, Oliver Kiddle wrote:


>  manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man)
>  export MANPATH
>

That's bad and does not belong to generic .zshrc. It blindly overwrites
systems defaults and should be removed. The location of man pages is too
system-dependent. And if anybody installs its own man pages, he knows how
to access them :-)

-andrej


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

* Re: example startup file
  2001-05-09  5:43 ` Andrej Borsenkow
@ 2001-05-09  6:38   ` Dan Nelson
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Nelson @ 2001-05-09  6:38 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: zsh-workers

In the last episode (May 09), Andrej Borsenkow said:
> On Tue, 8 May 2001, Oliver Kiddle wrote:
> >  manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man)
> >  export MANPATH
> 
> That's bad and does not belong to generic .zshrc. It blindly
> overwrites systems defaults and should be removed. The location of
> man pages is too system-dependent. And if anybody installs its own
> man pages, he knows how to access them :-)

If anything, use 

whence manpath 2>/dev/null && export MANPATH=`manpath`

which will use the system-generated manpath if one is available.

-- 
	Dan Nelson
	dnelson@emsphone.com


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

* Re: example startup file
  2001-05-08 19:56 ` Bart Schaefer
@ 2001-05-09 16:46   ` Oliver Kiddle
  2001-05-09 17:24     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2001-05-09 16:46 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> 
> However, if you know (as in the example) that fpath is non-empty, you can
> just do one loop like this:
> 
>     for func in $^fpath/*(N-.x:t); autoload $func

That looks good. I've switched it to that with a comment about the
non-empty issue.

> I use:
> 
>     typeset -U path cdpath fpath manpath

So do I and I'll add it to the example. I was just suprised that
compinit added duplicates.

> That never was csh-compatible.  This is:
> 
>     setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }

ok. I'll put it in even though it ceases to be a nice simple example.
I'd like yp and yu from Functions/Example in here instead because
they are simple and easy to understand.

Has anyone got a useful and very short user-defined zle widget we could
add?

> > +freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
> 
> I'd throw in a check that the argument actually is a function before calling
> unfunction on it.

That would either need zmodloading zsh/parameter, a redirected which or
redirected stderr from unfunction. I think I'd prefer to keep it simple,
I'm even tempted to remove the while loop. If you prefer, either change
it or remove the function, I'm not really bothered but I've left it as
above for now.

Andrej wrote:

> >  manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man)

> That's bad and does not belong to generic .zshrc. It blindly overwrites

I thought it was meant to be an example really as opposed to being
generic but judging from the comment at the top, maybe I'm wrong. That
isn't a line I added it was there before and I think it serves a useful
purpose in showing that you can setup your manpath there. I also think
it wouldn't be a bad thing if the examples break lots of things to
force them to be read before being used.

If you really want to remove those lines, I don't mind but following
the same principle much of zlogin and all of zshenv would also have to
go too.

Anyway, I'm going to be away for a few days so I'll commit this now
before I forget. Patch is to be applied on top of the previous. I also
added a few zmodload -a commands.

> zefram wrote:
> >       directory stack access with =num
> It was changed to ~num some time ago.

Ok, thanks, I've also updated that line before it is forgotten.

Oliver

Index: Etc/FEATURES
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/FEATURES,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 FEATURES
--- Etc/FEATURES        1999/04/15 18:05:37     1.1.1.1
+++ Etc/FEATURES        2001/05/09 16:41:27
@@ -5,13 +5,13 @@
 very close to ksh/sh grammar, with csh additions
 most features of ksh, bash, and tcsh
 can emulate ksh or POSIX sh
-81 builtins, 102 options, 162 key bindings
+100 builtins, 145 options, 166 key bindings
 short for loops, ex: for i (*.c) echo $i
 select
 shell functions
 conditional expressions (test builtin, [ ... ], and ksh-style [[ ... ]])
 global aliases (may be expanded anywhere on the line)
-directory stack access with =num
+directory stack access with ~num
 process substitution (vi =(cmd) edits the output of cmd)
 generalized pipes (ls foo >>(cmd1) 2>>(cmd2) pipes stdout to cmd1
   and stderr to cmd2)
--- zshrc       Tue May  8 18:42:07 2001
+++ zshrc       Wed May  9 17:30:10 2001
@@ -41,20 +41,20 @@
 alias lsa='ls -ld .*'
 
 # Shell functions
-setenv() { export $1=$2 }  # csh compatibility
+setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }  # csh compatibility
 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
 
 # Where to look for autoloaded function definitions
 fpath=($fpath ~/.zfunc)
 
-# Autoload all shell functions from all directories
-# in $fpath that have the executable bit on
-# (the executable bit is not necessary, but gives
-# you an easy way to stop the autoloading of a
-# particular shell function).
-#for dirname in $fpath; do
-#  autoload $dirname/*(.x:t)
-#done
+# Autoload all shell functions from all directories in $fpath (following
+# symlinks) that have the executable bit on (the executable bit is not
+# necessary, but gives you an easy way to stop the autoloading of a
+# particular shell function). $fpath should not be empty for this to work.
+for func in $^fpath/*(N-.x:t); autoload $func
+
+# automatically remove duplicates from these arrays
+typeset -U path cdpath fpath manpath
 
 # Global aliases -- These do not have to be
 # at the beginning of the command line.
@@ -93,6 +93,12 @@
 setopt   autoresume histignoredups pushdsilent noclobber
 setopt   autopushd pushdminus extendedglob rcquotes mailwarning
 unsetopt bgnice autoparamslash
+
+# Autoload zsh modules when they are referenced
+zmodload -a zsh/stat stat
+zmodload -a zsh/zpty zpty
+zmodload -a zsh/zprof zprof
+zmodload -ap zsh/mapfile mapfile
 
 # Some nice key bindings
 #bindkey '^X^Z' universal-argument ' ' magic-space


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

* Re: example startup file
  2001-05-09 16:46   ` Oliver Kiddle
@ 2001-05-09 17:24     ` Bart Schaefer
  2001-05-09 17:34       ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2001-05-09 17:24 UTC (permalink / raw)
  To: Oliver Kiddle, zsh-workers

On May 9,  5:46pm, Oliver Kiddle wrote:
}
} Has anyone got a useful and very short user-defined zle widget we could
} add?

insert-octal () {
  # Insert the ASCII value in octal of the next character typed

  local c
  typeset -i 8 o
  typeset -Z 3 x        # Why doesn't "typeset -Z 3 -i 8 o" work?

  if read -k 1 c; then
    ((o=#c))
    x=${o#8#}
    LBUFFER="$LBUFFER\\$x"
  fi
}


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: example startup file
  2001-05-09 17:24     ` Bart Schaefer
@ 2001-05-09 17:34       ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2001-05-09 17:34 UTC (permalink / raw)
  To: Zsh hackers list

Bart wrote:
>   typeset -Z 3 x        # Why doesn't "typeset -Z 3 -i 8 o" work?

This has always been a horrible botch up.  There's only one set of numbers
in the param struct, and only one number passed down with a typeset
options: either it functions as a base, or it functions as a fill size.
It can be fixed at the expense of a larger struct pm and with more
communication between the builtin parser and bin_typeset().

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


**********************************************************************
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

end of thread, other threads:[~2001-05-09 17:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-08 17:58 example startup file Oliver Kiddle
2001-05-08 18:17 ` Zefram
2001-05-08 19:56 ` Bart Schaefer
2001-05-09 16:46   ` Oliver Kiddle
2001-05-09 17:24     ` Bart Schaefer
2001-05-09 17:34       ` Peter Stephenson
2001-05-09  5:43 ` Andrej Borsenkow
2001-05-09  6:38   ` Dan Nelson

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