简体   繁体   English

将评估的别名命令保存在bash / zsh历史记录中

[英]Save evaluated alias command in bash/zsh history

I am wondering if it would be possible to store evaluated commands in history instead of the alias. 我想知道是否有可能在历史记录而不是别名中存储评估的命令。 Especially with many user having their aliases it is difficult to have an overview of them when searching in history. 尤其是对于许多拥有别名的用户,在历史记录中进行搜索时很难对其进行概述。

Example: 例:

$ alias a2re="apache2ctl restart"
$ a2re
$ history
    1  a2re

Instead of: 代替:

$ history
    1 apache2ctl restart

Does anyone know if there is such an option for bash/zsh? 有谁知道bash / zsh是否有这样的选择?

Not that I am aware of. 不是我知道的。 bash , at least, records what is in the input buffer (after undergoing history expansion) just prior to hitting Enter to execute the command. 至少在单击Enter执行命令之前, bash至少记录了输入缓冲区中的内容(经历了历史扩展之后)。 One workaround is to tell the shell to expand the line before you commit to executing it. 一种解决方法是承诺执行之前告诉外壳扩展该行。 After you type the alias, type Meta - Control - e (where Meta is either your Alt or Esc key, depending on your setup). 键入别名后,键入Meta - Control - e (其中Meta是您的AltEsc键,具体取决于您的设置)。 This will expand the line just like the shell would, but leaves the command on the command line for further editing before executing it by hitting Enter . 这将像shell一样扩展该行,但是在执行该命令之前,请通过按Enter将该命令留在命令行上以进行进一步编辑。 Then the expanded form of the command is saved in your history. 然后,命令的扩展形式将保存在您的历史记录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM