开发者

Is there a convenient autocomplete in unix for previously entered commands like in MATLAB?

I like how you can autocomplete previous commands in MAT开发者_JS百科LAB by typing a few words and pressing the key. The same works in python IDLE. Is there an equivalent of that in unix shells? If it helps, I'm using csh.


I don't know in csh, but in bash you have several commands to manipulate the history. In particular, CTRL-R could be useful. See more in:

http://www.delorie.com/gnu/docs/bash/bashref_97.html


In csh, you can access previous commands using history substitution (see man csh).

Examples:

% echo $history
% set history=20
% echo a
a
% pwd
/some/dir
% !e
echo a
a
% history
     9  echo a
    10  pwd
    11  echo a
    12  history
% !-3
pwd
/some/dir
% !e:s/a/wow/
echo wow
wow
%


You can set an alias like so:

alias prev 'history | grep \!^'

when you type prev foo, it searches your history for all occurrences of foo and spits out a list like so:

23 17:43 foo bar
47 19:29 foo fighters

where the first column is the command number, the second is the time it was executed and the last is the command. You can re-execute the previous command by typing !<command number>


rlwrap adds gnu readline editing to any console command.


Same as previous answer by Jesus, but with more clarification

Hit CTRL + R start typing and voila! (you can hit CTRL+R more times to cycle matches)

Double answer but if people are speed reading like me, they will skip the answer since I read words "tool" and saw link I assumed it is 3rd party tool, but it comes built in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜