把每次新增專案的流程自動化,在 terminal 輸入 create [專案名稱]
就可以做到以下流程:
新增資料夾 --> git init --> 新增git repo --> git remote 等 --> 開啟vscode
[20230327更新]: 若Github有設定兩步驟驗證,會無法使用網頁爬蟲的方式新增並連結到github repo 只能改用script建立local repo並等待使用者輸入git remote url。
Automate my process of creating a new project with entering create-github <project name>
in terminal to achieve the following process:
create project folder --> git init --> create git repository --> git remote etc. --> open vscode
Custom command has two function:
create()
: Only create a new local repository, you need to enter remote repository url (e.g. github/gitlab) by yourself.create-github()
: If you haven't set up two-way authentication, you can use this function to create a new repository and link it to github automatically.
Steps:
- Create a new folder for your custom command
- Copy
my-cmd.sh
to the folder you create - Open
my-cmd.sh
and change the following variable to your local setting:CMDIR
: your custom command folder pathPROJECT_ROOT
: your project root path
- Add execution permission
chmod +x .my-cmd.sh
- Add custom command to
~/.zshrc
vim ~/.zshrc
# add
source ~/your-custom-command-folder-path/.my-cmd.sh
- Source zshrc
source ~/.zshrc
Then you can run the commands in my-cmd.sh
by using th following command:
create <project-name>
OR
create-github <project-name>