cra*_*sic 27 command-line bash
对于那些不在 ubuntu 上进行 python 编程的人来说,ipython 是一个强大的 python shell,但它有一个惊人的功能,它不仅基于已知名称自动完成(即,当你按 Tab 时 bash 所做的方式相同),但是,如果您开始键入命令并向上按,它不会滚动浏览整个历史记录(如 bash),而只会滚动以相同字母字符串开头的最近命令。
因此,如果您执行了一些长命令,例如scp -r -P 8000 -l user server.com:~/dir/to/copy ./后跟其他几个命令。如果您开始输入scp并按下,bash 将显示之前显示的命令,而不仅仅是滚动整个历史记录。
bash 有这样的扩展吗?或者有没有提供这种功能的外壳?
ak2*_*ak2 30
Bash 也有这个功能,但默认情况下它没有启用。您可以通过将其粘贴到~/.inputrc以下内容将其绑定到光标上/下:
"\e[A": history-search-backward
"\e[B": history-search-forward
Run Code Online (Sandbox Code Playgroud)
我更喜欢将它绑定到Ctrl+up/down:
"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward
Run Code Online (Sandbox Code Playgroud)
编辑:要保留ctrl+left并ctrl+right在整个单词中前后移动,还可以在~/.inputrc文件中包含这些行:
# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
Run Code Online (Sandbox Code Playgroud)
并且不要忘记 bash 中奇妙的历史扩展快捷方式。1
I'm posting some excerpts from the manpage, in case you haven't tattooed them on your arm (or memorized them).
Event Designators
An event designator is a reference to a command line entry in the his?
tory list.
! Start a history substitution, except when followed by a blank,
newline, carriage return, = or ( (when the extglob shell option
is enabled using the shopt builtin).
!n Refer to command line n.
!-n Refer to the current command line minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containing string. The trail?
ing ? may be omitted if string is followed immediately by a new?
line.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1
with string2. Equivalent to ``!!:s/string1/string2/'' (see Mod?
ifiers below).
!# The entire command line typed so far.
Run Code Online (Sandbox Code Playgroud)
I frequently use the ability to refer to the last 'word' of the previous command. E.g.,
mkdir /foo/shmoo/adir.horribilus.foo
cp file1 file2 file3 file4 !$
ls -l !$
Run Code Online (Sandbox Code Playgroud)
In both cases here, the !$ matches /foo/shmoo/adir.horribilus.foo .
1... which were taken from csh. To mitigate the scope of bash's feature theft, the bash man page says
The shell supports a history expansion feature that is similar to the
history expansion in csh.
Run Code Online (Sandbox Code Playgroud)
So, it's "similar". Any of this might break in csh or tcsh. Or whichever csh descendent you are not using due to the fact that it isn't as wonderful as bash .