我如何在每个命令上发送消息,例如“致命:必须在工作树中运行此操作”。在.git文件夹中
在.git
文件夹中,消息
致命:该操作必须在标题中的工作树中运行
在我的输入中,例如ls
,cd。
,甚至echo hi
等等。
我的问题不是如何解决这个问题,或者不询问为什么它出现。
我想出于我自己的目的将消息(在任何命令上)发送给用户(pwd
在指定的位置中,例如/home/home/user_name/target
)。 如何安装?我的环境是macos。 (如果我得到任何线索,我会在任何其他OSS上找到解决方案)
(我的问题可能与git无关)
In a .git
folder, the message
fatal: This operation must be run in a work tree
in the title comes on my input such as ls
, cd .
, even echo hi
and so on.
My question is NOT how to solve this or NOT asking why it comes out.
I want to send messages to users (on any commands) like this for my own purpose (when PWD
is in a specified location such as /home/user_name/target
if possible).
How is it installed? My environment is macOS. (If I get any clues, I will find solutions on any other OSs)
(My question may not be related to Git)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(对我来说)并不清楚您为什么想要这个。
简短的答案是否,bash,cshell,zsh,ksh等,没有这样的钩子来调用函数,并决定不根据该函数的返回值执行命令。
要执行这样的事情,您需要自己的外壳(解释器),并且您的代码将执行您在.git目录中的检查并在您决定需要打印时打印该消息时要执行的检查。
包装外壳命令似乎很微不足道,但完整的外壳功能不是。
注意:下面未测试
这只是一个播放示例,因为真实的外壳/口译员处理多个带有重定向,子壳,终端对照组,暂停,简历等的
命令要执行此操作(仍然),然后寻找bash或您喜欢的外壳的来源并实现它。 :-)
It's not (to me) clear why you would want this.
The short answer is no, the bash, cshell, zsh, ksh, etc, do not have such a hook to make a call to a function and decide to not execute a command based on the return value of that function.
To do such a thing you would need your own shell (interpreter), and your code would perform the checks that you want to perform when your in the .git directory and print that message whenever you decide it needs to be printed.
Wrapping shell commands appears to be trivial, but full shell functionality is not.
NOTE: Below was not tested
This is only a play example, however, because real shell/interpreters handle multiple commands with redirection, sub-shells, terminal control groups, Suspend, Resume, etc.
If you wanted to do this (still) then look for the source for bash or your favorite shell and implement it. :-)