Spawn commands with Git. (Self use.)
I think you muse have used Git Aliases. Here is a git alias usage sample:
git config --global alias.st status
This means that, for example, instead of typing
git status, you just need to type
git st. So, where does git store this alias information? you might have already guessed the answer ——
~/.gitconfig (For macOS users).
.gitconfig and figure out:
[alias] st = status
Okay, this is how git store aliases, so is the aliases just like this? Of course not, you can also write
Shell in Git Aliases
A quick commit process would be like this:
git add . git commit -m "commit message"
So can we merge it into a git instruction? of course we can. According to Git Documentation:
Git simply replaces the new command with whatever you alias it for. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a
!character. This is useful if you write your own tools that work with a Git repository.
So you can use git command line to config it:
git config --global alias.commitX '!sh -c " git ad; git commit -m "$*" ;"'
Or type it in the
[alias] commitX = "!sh -c \" git ad; git commit -m \"$*\" ;\""
Node.js in Git Aliases
With the above foundation, we can write a sample quickly:
[alias] node-scripts = "!node app.js"
If I have some scripts in directories, I hope they can be mapped to git commands automatically. e.g.
app.sh => git app kill-node.js => git kill-node
That's what this repo mainly for. besides of git commands mapping, it also provides some instructions to help you backup or setup the git configurations.
In this repo, all scripts are placed in
Setup global git config, which includes
yarn setup-git yarn setup-gitignore
This step is often used when you kick off programming at a new computer.
~/.gitconfig up to