You can determine the character sequence emitted by a key by pressing Ctrl-v at the command line, then pressing the key you're interested in. On my system for F12, I get ^[[24~.
The ^[ represents Esc.
Different types of terminals or terminal emulators can emit different codes for the same key.

At a Bash prompt you can enter a command like this to enable the key macro so you can try it out.

  1. bind '"\e[24~":"foobar"'

Now, when you press F12, you'll get "foobar" on the command line ready for further editing. If you wanted a keystroke to enter a command immediately, you can add a newline:

  1. bind '"\e[24~":"pwd\n"'

Now when you press F12, you'll get the current directory displayed without having to press Enter. What if you've already typed something on the line and you use this which automatically executes? It could get messy. However,
you could clear the line as part of your macro:

  1. bind '"\e[24~":"\C-k \C-upwd\n"'

The space makes sure that the Ctrl-u has something to delete to keep the bell from ringing.

Once you've gotten the macro working the way you want, you can make it persistent by adding it to your ~/inputrc file.
There's no need for the bind command
or the outer set of single quotes:

  1. "\e[24~":"\C-k \C-upwd\n"

Edit:

You can also create a key binding that will execute something without disturbing the current command line.

  1. bind -x '"\eW":"who"'

Then while you're typing a command that requires a username, for example, and you need to know the names of user who are logged in, you can press Alt-Shift-W and the output of who will
be displayed and the prompt will be re-issued with your partial command intact and the cursor in the same position in the line.

Unfortunately, this doesn't work properly for keys such as F12 which output more than two characters. In some cases this can be worked around.

The command (who in
this case) could be any executable - a program, script or function.

bash下如何使用bind[En]的更多相关文章

  1. Git bash下中文乱码问题

    Git bash下中文乱码--解决方案 解决办法1: 在git bash下,右键 出现下图,选择options: 选择"Text" 将Character set设置为 UTF-8 ...

  2. bash下几个替换运算符的区分

    bash下几个替换运算符的区分 2012-03-21 22:20:54 分类: Python/Ruby 一直对四个替换运算符比较的迷惑,分布太清楚,记下来避免再次遗忘:   ${name:-word} ...

  3. bash下. : () {} [] [[]] (())的解释 (非原创,侵删)

    Copy from http://blog.chinaunix.net/uid-20380484-id-1692999.html bash下有很多像{}.[]等一些符号命令,下面是我对一些常用的符号命 ...

  4. bash下输入命令的几个常用快捷键

    ------------------------------------------ 先区分下vi里的命令   快速在行里移动光标 b 是往前部一个单词一个单词的移动 e 是往后部一个单词一个单词的移 ...

  5. bash下. : () {} [] [[]] (())的解释

    bash下有很多像{}.[]等一些符号命令,下面是我对一些常用的符号命令的学习笔记,若有错误或纰漏望各位兄弟指正. 一..(source).(点)与source命令一样,从文件中读取并执行命令,无论该 ...

  6. ES6下的Function.bind方法

    在JavaScript的使用中,this的指向问题始终是一个难点.不同的调用方式,会使this指向不同的对象.而使用call,apply,bind等方式,可改变this的指向,完成一些令人惊叹的黑魔法 ...

  7. Git Bash下实现复制粘贴等快速编辑功能

    在windows下使用Git Bash会经常用到选中.复制.粘贴等功能,但是一般用的方法会很复杂,笔者经过查阅一些资料,特整理一些常见编辑功能的实现方法. (1)默认方法: 单击左上角的logo ic ...

  8. Git 使用问题 - win7 git bash下git pull失败

    win7 旗舰版,从github上pull代码时,git bash命令出现错误 Administrator@rust-PC /g/rust_proj/cardslib (master) $ git - ...

  9. git bash 下操作文件及文件夹命令

    1, cd : change directory的简写,改变目录的意思,就是切换到哪个目录下, 如 cd e:\fff  切换 E 盘下面的fff 目录. 当我们用cd 进入文件夹时,我们可以使用 通 ...

随机推荐

  1. bash shell while语法

    在编写脚本时,一定要注意空格 基本语法: while [ condition ] do command1 command2 command3 done condition为true时命令1到命令3将会 ...

  2. Struts 1 之<bean>标签库

    <bean:write>标签 <bean:write>能输出request.session.application.page四个域中能访问到的变量,与EL表达式不同的是,如果变 ...

  3. SSH框架实现仿淘宝购物demo

    还记得六月份实习的时候,曾经做过一个电商的项目,项目里面需要实现类似淘宝购物车的移动端的demo,随着项目的进行,再一次跟购物车碰面,但是今天呢,不是移动端的需求,如何使用SSH框架实现类似淘宝的购物 ...

  4. 指令汇B新闻客户端开发(五) ShareSdk的使用

    ShareSdk是一个分享按钮的开源框架,我们首先可以去mob的官网下载这个控件.mob官网,然后找到sdk下载那一栏, 下载下来之后点击这个.jar文件就会有一个弹窗,填写自己的应用包名和要哪些分享 ...

  5. XML Schema

    XML Schema 是基于 XML 的 DTD 替代者. XML Schema 描述 XML 文档的结构. XML Schema 语言也称作 XMLSchema 定义(XML Schema Defi ...

  6. 安卓java.lang.IllegalStateException: The specified child already has a parent.解决方案

    在使用ViewPager的时候遇到一个错误java.lang.IllegalStateException: The specified child already has a parent. You ...

  7. python的u'字符串"(字符编码):字符串前有u,表示字符串以unicode格式存储

    举个例子 >>> s = u'\u6ce8\u91ca' >>> s u'\u6ce8\u91ca' >>> print s 注释 >> ...

  8. Handler,MessageQueue Loop 和Message的原理解析

    先介绍和handler一起工作的几个组件 Handler的方法介绍 代码示例 package liu.peng.weather; import java.util.Timer; import java ...

  9. 【一天一道LeetCode】#258. Add Digits

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  10. Ubuntu15.10下如何使用EasyGui模块开发Python GUI

    偶然的一个机会,发现了github上的这个开源的项目,easygui for python(一个基于TKinter的模块) 感觉很是惊讶,原来python也可以这么简单的开发出一些GUI界面(究其原因 ...