bash下如何使用bind[En]
2014-05-25 12:47
239 查看
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
The
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.
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:
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:
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
There's no need for the
or the outer set of single quotes:
Edit:
You can also create a key binding that will execute something without disturbing the current command line.
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
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 (
this case) could be any executable - a program, script or function.
^[[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.
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:
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:
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
~/inputrcfile.
There's no need for the
bindcommand
or the outer set of single quotes:
"\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.
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
whowill
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 (
whoin
this case) could be any executable - a program, script or function.
相关文章推荐
- bash下如何使用bind[En]
- bash下如何使用bind[En]
- BOOST::bind 如何使用
- 如何在电脑上启动bash终端,并使用python命令
- How to: Shellcode to reverse bind a shell with netcat(如何使用netcat进行shellcode反向链接)
- 如何在Mac中使用Android SDK,使用adb工具避免出现-bash: adb: command not found
- 【云计算】Docker 镜像如何设置语言环境?bash: warning: setlocale: LC_ALL: cannot change locale (en_US)
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 如何使用Git Bash Here,将本地项目传到github上
- bash下使用bind定义快捷键的自动完成功能
- 【C++ STL学习与应用总结】22: 函数组合之1:如何使用std::bind (since C++11)
- Bash中使用管道时如何正确捕捉返回值
- 如何使用netcat或bash创建反向shell来执行远程root命令
- 如何使用NetCat或BASH创建反向Shell来执行操作
- 关于Ubuntu下 如何在bash使用phpstudy 套件中的php 的方法
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 如何使用Rebase以及bind来重定位和绑定dll
- 如何手动编译bind,如何使用view实现智能DNS解析,以及如何对DNS服务器进行压力测试。
- javascript如何使用bind指定接收者
- 如何在Mac中使用Android SDK,使用adb工具避免出现-bash: adb: command not found