简体   繁体   English

在运行交互式命令之前和之后运行命令

[英]Run a command before and after running an interactive command

I have a command say intr-cmd which opens an interactive console for web framework.我有一个命令说intr-cmd它为 web 框架打开一个交互式控制台。 But I need to run command cmd-a before and cmd-b after running the intr-cmd manually.但是我需要在手动运行intr-cmd之前和cmd-b之前运行命令cmd-a These commands change some files for intr-cmd to run.这些命令更改了一些文件以供intr-cmd运行。

How can I code this in Bash such that I only have to run intr-cmd and these commands are run before and after it.如何在 Bash 中对此进行编码,这样我只需要运行intr-cmd并且这些命令在它之前和之后运行。

Edit: Some explanation编辑:一些解释

intr-cmd opens an interactive console but it first reads a file of currently installed plugins to load them. intr-cmd打开一个交互式控制台,但它首先读取当前安装的插件文件以加载它们。 But there is a plugin which is installed on production but is not working on the local environment and it is not necessary for my work.但是有一个插件安装在生产环境中,但不能在本地环境中运行,这对我的工作来说不是必需的。 but the plugins file is committed into the git.但是插件文件被提交到 git 中。 so I have to comment on the plugin then run the intr-cmd and then uncomment that line in the file.所以我必须对插件进行评论,然后运行intr-cmd ,然后在文件中取消注释该行。

I want to automate this step so that it does not accidentally get committed to the git.我想自动化这一步,这样它就不会意外地提交给 git。

You can create a function intr-cmd , which replaces the general intr-cmd command, as explained here .您可以创建一个 function intr-cmd ,它会替换一般的intr-cmd命令,如此所述。

I should like like:我喜欢:

intr-cmd()
{
  cmd-a
  /path/intr-cmd
  cmd-b
}

(Obviously you need to fill in the right path.) (显然你需要填写正确的路径。)

I tried to flag your question as a duplicate, but as the link refers to another StackExchange forum, this wasn't allowed, hence this answer.我试图将您的问题标记为重复,但由于链接指向另一个 StackExchange 论坛,因此这是不允许的,因此是这个答案。

In your case, instead of changing intr-cmd each time you need it, you could create a git branch (possibly in a specific clone of your git repo) for your testing environment with a modified version of intr-cmd , and/or a modified version of the plugin list.在您的情况下,不是每次需要时都更改intr-cmd ,而是可以使用修改版本的intr-cmd和/或插件列表的修改版本。

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

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