zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-users@zsh.org>
Subject: Re: ZSH's way to bind function to a key in a script?
Date: Wed, 9 Mar 2011 14:11:39 +0000	[thread overview]
Message-ID: <20110309141139.09b8f984@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <dc64f3246d1cac04e3dfa582a9e1ad16.squirrel@gameframe.net>

On Wed, 9 Mar 2011 15:46:44 +0200
<nix@myproxylists.com> wrote:
> Hi everyone. I was reading last night about "bindkey" etc. , and i
> could not get it working.
> 
> #!/bin/zsh
> 
> function foo () {
> 
> echo "Foo ooo"
> }
> 
> In this script, how to bind function "foo" to a key. So lets say i
> press the Space button and it should trigger foo?

The standard examples of bindkey assume you're binding editor commands
rather than normal commands, i.e. something that helps you edit a
command line.

To bind a command to a keystroke, you need the "-s" option to bindkey.
However, note it's doing something rather different --- basically just
dumping the keys you type into the command line.  One idiom for running
"foo" this way is to use ^q to ensure there's nothing else in the buffer
(if there is, you don't lose it, you get it back after running foo), and
put a newline at the end.  Luckily you can use the same abbreviations
for keys as in the keystroke part of the command:

bindkey -s '<keystroke>' '^qfoo\n'

This assumes ^q is bound to the editor command push-line.  You can
remove the ^q if you only want to use this on an empty command line.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


      parent reply	other threads:[~2011-03-09 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 13:46 nix
2011-03-09 14:01 ` Jérémie Roquet
2011-03-09 14:05   ` Jérémie Roquet
     [not found]   ` <34287570baba3024c8cffea8be3da248.squirrel@gameframe.net>
2011-03-09 14:35     ` Jérémie Roquet
2011-03-10  0:22       ` Wendell Hom
2011-03-09 14:11 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110309141139.09b8f984@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).