简体   繁体   English

如何为 VS Code 创建自定义终端命令

[英]How To Create Custom Terminal Command for VS Code

I use git (like most people) for my projects in VS Code.我在 VS Code 中的项目中使用 git(和大多数人一样)。 However, I find it a hassle to first add the files, then commit them.但是,我发现首先添加文件然后提交它们很麻烦。 So what I want to do is create a terminal command (maybe like commit "message" ).所以我想做的是创建一个终端命令(可能像commit "message" )。 What this command should do is run the following: git add .这个命令应该做的是运行以下命令: git add . then git commit -m plus the message they wrote in the command.然后git commit -m加上他们在命令中写的消息。 From what I've seen, this shouldn't be too much of a hassle.据我所知,这应该不会太麻烦。

Thanks in advance!提前致谢!

You can add these commands as a script in your package.json.您可以将这些命令作为script添加到 package.json 中。 To get access to the command line if your package.json is used in a Docker container you use -bash in front of your script, otherwise not necessary as far as I know.如果您的 package.json 在 Docker 容器中使用,要访问命令行,请在脚本前使用-bash ,否则就我所知不需要。

To run the script you use npm run name-of-my-script .要运行脚本,请使用npm run name-of-my-script

You can also collect your command line instructions in a bash file and run the file from package.json as discussed here: Running bash scripts with npm您还可以在 bash 文件中收集命令行指令并从 package.json 运行该文件,如下所述: 使用 npm 运行 bash 脚本

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

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