应该可以通过让 ALT+UP 生成cdspace..ENTER与宏定义等效的连续键盘输入来做到这一点。但不知道具体怎么做。
Gil*_*il' 19
要按字面意思执行您的要求,请将以下行放入您的~/.inputrc
:
"\e\e[A": "cd ..\n"
Run Code Online (Sandbox Code Playgroud)
这\e\e[A
是当您按Alt+时终端发送的字节序列Up(\e
被解析为转义字符),某些终端可能会发送\e[1;3A~
或其他一些序列。要找出您的终端发送的序列,请运行cat
并按下 键(escape 将显示为^[
)。
在 bash 中,原则上您可以将密钥绑定到 shell 代码,因此理论上这应该可以工作:
bind -x '"\e\e[A":cd ..'
Run Code Online (Sandbox Code Playgroud)
但是,从 bash 4.2 开始,由于难以修复的实现错误,它不起作用。Zsh 专家Stéphane Chazelas有一个解决方法:
bind -x '"\201":cd ..'
bind '"\e\e[A":"\201"'
Run Code Online (Sandbox Code Playgroud)
效果有些混乱,因为提示没有重绘。
在 bash ?4 中,添加shopt -s autocd
到您的~/.bashrc
. 然后只需输入 即可更改到父目录(或任何目录)..
,而无需键入cd
命令。