* ZSH's way to bind function to a key in a script? @ 2011-03-09 13:46 nix 2011-03-09 14:01 ` Jérémie Roquet 2011-03-09 14:11 ` Peter Stephenson 0 siblings, 2 replies; 6+ messages in thread From: nix @ 2011-03-09 13:46 UTC (permalink / raw) To: zsh-users 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? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ZSH's way to bind function to a key in a script? 2011-03-09 13:46 ZSH's way to bind function to a key in a script? 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:11 ` Peter Stephenson 1 sibling, 2 replies; 6+ messages in thread From: Jérémie Roquet @ 2011-03-09 14:01 UTC (permalink / raw) To: zsh-users; +Cc: nix Hi, 2011/3/9 <nix@myproxylists.com>: > 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? zle -N foo bindkey ' ' foo Best regards, -- Jérémie ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ZSH's way to bind function to a key in a script? 2011-03-09 14:01 ` Jérémie Roquet @ 2011-03-09 14:05 ` Jérémie Roquet [not found] ` <34287570baba3024c8cffea8be3da248.squirrel@gameframe.net> 1 sibling, 0 replies; 6+ messages in thread From: Jérémie Roquet @ 2011-03-09 14:05 UTC (permalink / raw) To: zsh-users; +Cc: nix 2011/3/9 Jérémie Roquet <arkanosis@gmail.com>: > zle -N foo > bindkey ' ' foo Or bindkey -s ' ' 'foo\n' …if you just want to emulate an user input. -- Jérémie ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <34287570baba3024c8cffea8be3da248.squirrel@gameframe.net>]
* Re: ZSH's way to bind function to a key in a script? [not found] ` <34287570baba3024c8cffea8be3da248.squirrel@gameframe.net> @ 2011-03-09 14:35 ` Jérémie Roquet 2011-03-10 0:22 ` Wendell Hom 0 siblings, 1 reply; 6+ messages in thread From: Jérémie Roquet @ 2011-03-09 14:35 UTC (permalink / raw) To: zsh-users; +Cc: nix 2011/3/9 <nix@myproxylists.com>: > Can't get it working in a script. Tried both vt100/xterm terminals but nada. > My purpose is this: > > while [ : ] ; do > > ... > > A user press the space button and he will see the script progress .... > > done Then it's unrelated to bindkey ;-) Try this: while [ : ]; do read -ks a [[ $a = ' ' ]] && foo done Have a look at “man zshbuiltins” for more about the “read” builtin. Best regards, -- Jérémie ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ZSH's way to bind function to a key in a script? 2011-03-09 14:35 ` Jérémie Roquet @ 2011-03-10 0:22 ` Wendell Hom 0 siblings, 0 replies; 6+ messages in thread From: Wendell Hom @ 2011-03-10 0:22 UTC (permalink / raw) To: Jérémie Roquet, zsh-users; +Cc: nix [-- Attachment #1: Type: text/plain, Size: 1019 bytes --] When using "read -k key" I am matching against normal keys with if [ $key = '?' ] simple control characters like tabs with if (( #key == ##\t )) Ctrl + key sequences with (( #key == ##\C-u )) But how do I match against Alt + key sequences? Thanks, Wendell ________________________________ From: Jérémie Roquet <arkanosis@gmail.com> To: zsh-users@zsh.org Cc: nix@myproxylists.com Sent: Wed, March 9, 2011 6:35:48 AM Subject: Re: ZSH's way to bind function to a key in a script? 2011/3/9 <nix@myproxylists.com>: > Can't get it working in a script. Tried both vt100/xterm terminals but nada. > My purpose is this: > > while [ : ] ; do > > ... > > A user press the space button and he will see the script progress .... > > done Then it's unrelated to bindkey ;-) Try this: while [ : ]; do read -ks a [[ $a = ' ' ]] && foo done Have a look at “man zshbuiltins” for more about the “read” builtin. Best regards, -- Jérémie ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ZSH's way to bind function to a key in a script? 2011-03-09 13:46 ZSH's way to bind function to a key in a script? nix 2011-03-09 14:01 ` Jérémie Roquet @ 2011-03-09 14:11 ` Peter Stephenson 1 sibling, 0 replies; 6+ messages in thread From: Peter Stephenson @ 2011-03-09 14:11 UTC (permalink / raw) To: zsh-users 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-10 0:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-03-09 13:46 ZSH's way to bind function to a key in a script? 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
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).