Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh and RPM: a case of study (for me)



Francis GALIEGUE wrote:
> > > Another probably dumb example: I'm used to the bash key sequences
> > > (C-x|Esc)(!|@|~|/|$), how can I reproduce them in a simple manner?
> > 
> > You should find that many (most?) of them already work in zsh.  If you
> > find you're really missing any of them, let us know and I'm sure one
> > of us will be only to happy to help.
> > 
> 
> They don't seem to. For info, unless you already know it, what these
> sequences do in bash are:
> 
> Esc ! -> tries to complete the current word to a command name
> Esc $ -> same, but for environment variables, whether the word is
> preceeded by a $ or not
> Esc @ -> machine names (from /etc/hosts)
> Esc / -> file name
> Esc ~ -> a user name
> 
> C-x instead of Esc with one of the above will list matches and won't
> attempt any completion

Mais c'est pas de problème, ça.  The function in the patch allows those
bindings to work; some of them are already in use in zsh, so just follow
the instructions to add the remaining bindings if you want to override the
usual zsh ones.  Unfortunately this depends on my last patch for compdef
(well, fortunately really, or it wouldn't have been so easy), but it'll go
in 3.1.6-pws-7.

I've sent this to -workers instead of -users, where it's not much use.

--- Completion/Commands/_bash_completions.bash	Thu Sep 30 14:20:34 1999
+++ Completion/Commands/_bash_completions	Thu Sep 30 14:26:21 1999
@@ -0,0 +1,43 @@
+#compdef -K _bash_complete-word complete-word \e~ _bash_list-choices list-choices ^X~
+#
+# This function is for bash compatibility.  As some of the bash bindings
+# are already taken up in zsh, only Esc ~ and \C-x ~ are bound, and
+# you must add the rest by hand.  The bindings expected are:
+#
+# Esc ! -> command name
+# Esc $ -> environment variables
+# Esc @ -> machine names
+# Esc / -> file name
+# Esc ~ -> a user name
+# 
+# C-x instead of Esc with one of the above will list matches and won't
+# attempt any completion.
+#
+# The following will bind the remaining set; simply put it in .zshrc
+# after compinit is run.
+#
+# for key in '!' '$' '@' '/'; do
+#   bindkey "\e$key" _bash_complete-word
+#   bindkey "^X$key" _bash_list-choices
+# done
+#
+# If for some reason \e~ or ^X~ were already bound to something else,
+# that will not have been overridden, so you should add '~' to the
+# list of keys at the top of the for-loop.
+
+local key=$KEYS[-1]
+
+case $key in
+  '!') _main_complete _command_names
+       ;;
+  '$') compgen -E
+       ;;
+  '@') _main_complete _hosts
+       ;;
+  '/') _files
+       ;;
+  '~') _main_complete _users
+       ;;
+  *) _message "Key $key is not understood"
+     ;;
+esac
--- Doc/Zsh/compsys.yo.bash	Thu Sep 30 14:38:55 1999
+++ Doc/Zsh/compsys.yo	Thu Sep 30 14:40:07 1999
@@ -1170,6 +1170,26 @@
 following is a list of these and their default bindings.
 
 startitem()
+item(tt(_bash_completions))(
+This function is used by two widgets, tt(_bash_complete-word) and
+tt(_bash_list-choices).  It exists to provide compatibility with
+completion bindings in bash.  The last character of the binding determines
+what is completed: `tt(!)', command names; `tt($)', environment variables;
+`tt(@)', host names; `tt(/)', file names; `tt(~)' user names.  In bash, the
+binding preceeded by `tt(\e)' gives completion, and preceeded by `tt(^X)'
+lists options.  As some of these bindings clash with standard zsh
+bindings, only `tt(\e~)' and `tt(^X~)' are bound by default.  To add the
+rest, the following should be added to tt(.zshrc) after tt(compinit) has
+been run:
+
+example(for key in '!' '$' '@' '/' '~'; do
+  bindkey "\e$key" _bash_complete-word
+  bindkey "^X$key" _bash_list-choices
+done)
+
+This includes the bindings for `tt(~)' in case they were already bound to
+something else; the completion code does not override user bindings.
+)
 item(tt(_correct_filename (^XC)))(
 Correct the filename path at the cursor position.  Allows up to six errors
 in the name.  Can also be called with an argument to correct

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author