回显 zsh 中的所有别名
是否可以强制 zsh 在使用别名时回显所有别名引用的实际命令?
例如,假设我设置了以下别名:
# List direcory contents
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
当我执行它们时,我希望看到它们每个都打印所执行的实际命令。例如,我希望看到以下内容:
$ ll
executing: 'ls -l'
total 0
-rw-r--r-- 1 person staff 0 Feb 15 13:46 cool.txt
-rw-r--r-- 1 person staff 0 Feb 15 13:46 sweet.html
-rw-r--r-- 1 person staff 0 Feb 15 13:46 test.md
而不是以下内容:
$ ll
total 0
-rw-r--r-- 1 person staff 0 Feb 15 13:46 cool.txt
-rw-r--r-- 1 person staff 0 Feb 15 13:46 sweet.html
-rw-r--r-- 1 person staff 0 Feb 15 13:46 test.md
是否有一个命令可以添加到我的 zshrc 中以使所有别名都发生这种情况?我不想修改每个别名。
Is it possible to force zsh to echo the actual commands referred to by all aliases when they are used?
For example, say that I have the following aliases set:
# List direcory contents
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
When I execute them I would like to see each of them print the actual command that's executed. For example, I would like to see the following:
$ ll
executing: 'ls -l'
total 0
-rw-r--r-- 1 person staff 0 Feb 15 13:46 cool.txt
-rw-r--r-- 1 person staff 0 Feb 15 13:46 sweet.html
-rw-r--r-- 1 person staff 0 Feb 15 13:46 test.md
Rather than the following:
$ ll
total 0
-rw-r--r-- 1 person staff 0 Feb 15 13:46 cool.txt
-rw-r--r-- 1 person staff 0 Feb 15 13:46 sweet.html
-rw-r--r-- 1 person staff 0 Feb 15 13:46 test.md
Is there one command that I can add to my zshrc to get this to happen for all aliases? I would prefer not to have to modify every alias.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您愿意显示别名(如果别名是命令行上出现的第一个单词),您可以尝试将以下代码放入您的 .zshrc 中:
描述(跳过一些琐碎的事情):
更多信息参见
\e[0m' # Sequence that being echoed to terminal clears out color information whence -w cmd # Display type of the command in format “cmd: type” whence cmd # If “cmd” is an alias, then this command outputs alias value zle .accept-line # Call internal zle “accept-line” widget. This must be done or # every command will turn to no-op. You can, of course, replace # this with “eval $BUFFER” but I can’t say what will break in this case zle -N accept-line _-accept-line # Associate widget “accept-line” with function # “_-accept-line”. This makes this function responsible for accepting # lines.man zshbuiltins< /code> (
模拟
、从何而来
、本地
)、man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
)。更多信息参见
\e[32m' RESET_COLORS=man zshbuiltins< /code> (
模拟
、从何而来
、本地
)、man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
)。描述(跳过一些琐碎的事情):
更多信息参见
\e[0m' [[ "$(whence -w $FIRSTWORD 2>/dev/null)" == "${FIRSTWORD}: alias" ]] && echo -nEman zshbuiltins< /code> (
模拟
、从何而来
、本地
)、man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
)。描述(跳过一些琐碎的事情):
更多信息参见
\n'"${GREEN}Executing $(whence $FIRSTWORD)${RESET_COLORS}" zle .accept-line } zle -N accept-line _-accept-lineman zshbuiltins< /code> (
模拟
、从何而来
、本地
)、man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
)。描述(跳过一些琐碎的事情):
更多信息参见
man zshbuiltins< /code> (
模拟
、从何而来
、本地
)、man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
)。If you are fine with having aliases displayed if alias is the first word present on the command-line you can try to put the following code into your .zshrc:
Description (some trivial things skipped):
More info in
\e[0m' # Sequence that being echoed to terminal clears out color information whence -w cmd # Display type of the command in format “cmd: type” whence cmd # If “cmd” is an alias, then this command outputs alias value zle .accept-line # Call internal zle “accept-line” widget. This must be done or # every command will turn to no-op. You can, of course, replace # this with “eval $BUFFER” but I can’t say what will break in this case zle -N accept-line _-accept-line # Associate widget “accept-line” with function # “_-accept-line”. This makes this function responsible for accepting # lines.man zshbuiltins
(emulate
,whence
,local
),man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
).More info in
\e[32m' RESET_COLORS=man zshbuiltins
(emulate
,whence
,local
),man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
).Description (some trivial things skipped):
More info in
\e[0m' [[ "$(whence -w $FIRSTWORD 2>/dev/null)" == "${FIRSTWORD}: alias" ]] && echo -nEman zshbuiltins
(emulate
,whence
,local
),man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
).Description (some trivial things skipped):
More info in
\n'"${GREEN}Executing $(whence $FIRSTWORD)${RESET_COLORS}" zle .accept-line } zle -N accept-line _-accept-lineman zshbuiltins
(emulate
,whence
,local
),man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
).Description (some trivial things skipped):
More info in
man zshbuiltins
(emulate
,whence
,local
),man zshzle
(zle
,$BUFFER
),man zshparam
(${(z)}
).感谢 ZyX。我修改了他的答案,使其也适用于函数。这里是;
PS:它是在短时间内开发的。当然,它还可以改进。
Thanks to ZyX. I modified his answer to making it work for functions as well. Here it is;
PS: It is developed at short notice. For sure, it can be improved.