diff --git a/README.md b/README.md index b9e4f8a..59db571 100644 --- a/README.md +++ b/README.md @@ -78,15 +78,15 @@ cd {your_project} # notice: not cd posture project ! posture adjust ``` -### (1) git配置 -在执行完```adjust```命令时,```posture```会自动执行以下操作,确保git配置保持一致。 +### (1) git配置调整 +在执行完```adjust```命令时,```posture```会自动执行以下操作,确保大家的git配置保持一致。 ```bash # 忽略文件权限 git config --global --add core.fileMode false ``` -### (2) 代码规范 +### (2) 代码风格调整 在执行完```adjust```命令后,在您的项目根目录下,会生成一个```.editorconfig```文件,它会为您的IDE设置统一的代码规范。 diff --git a/include/function.sh b/include/function.sh index eaf8ee5..f1995ac 100644 --- a/include/function.sh +++ b/include/function.sh @@ -110,66 +110,3 @@ check_config(){ exit 1 fi } - -# start to adjust -adjust(){ - if ! check_config; then - print_error "adjust failed: check_config" - exit 1 - fi - - echo "正在调整中 (posture is adjusting)..." - - # git ignore fileMode - git config --global --add core.fileMode false - - # copy .editorconfig.template to your project - cp $POSTUREPATH/include/editor/.editorconfig.template ./ - - print_ok "> 完成 (done)" -} - -# start to set the global hook -hook(){ - if [ $1 == "" ]; then - print_error "缺少目录参数 (miss the directory param)" - exit 1 - fi - - projectDir=$1 - git config --global core.hooksPath ${projectDir}/include/hooks - chmod a+x ${projectDir}/include/hooks/commit-msg - chmod a+x ${projectDir}/include/hooks/post-checkout - chmod a+x ${projectDir}/include/hooks/post-merge - chmod a+x ${projectDir}/include/hooks/pre-commit - chmod a+x ${projectDir}/include/hooks/pre-push - - # 如果个别项目不需要使用全局的Hook, 可以在项目的根目录下重新配置git hooksPath: git config core.hooksPath .git/hooks - print_ok "hook successfully !" - print_warn "If your other projects don't need require the global Hooks, they can be reconfigured in the root directory of your other projects: git config core.hooksPath .git/hooks" -} - -# start to cancel the global hook -unhook(){ - git config --global core.hooksPath false -} - -# update your posture version -update_version(){ - currentDir=$(pwd) - cd $POSTUREPATH && git pull && cd $currentDir - # 判断是否拉取成功 - if [ $? -ne 0 ]; then - print_error "版本更新至最新版本失败 (Failed to update the version to the latest version)" - exit 1 - fi - print_ok "版本更新至最新版本成功 (update to latest version successfully)" -} - -# show status -status(){ - echo "The list of configuration" - echo "> lang = ${lang}" - echo "The list of states" - echo "> version = ${version}" -} diff --git a/posture b/posture index 5e382ed..ac294f4 100755 --- a/posture +++ b/posture @@ -5,20 +5,86 @@ if [ "${POSTUREPATH}" == "" ]; then fi . $POSTUREPATH/include/function.sh +# start to adjust +adjust(){ + if ! check_config; then + print_error "adjust failed: check_config" + exit 1 + fi + + echo "正在调整中 (posture is adjusting)..." + + # 1. git adjust + # git ignore fileMode + git config --global --add core.fileMode false + + # 2. code style adjust + # copy .editorconfig.template to your project + cp $POSTUREPATH/include/editor/.editorconfig.template ./ + + print_ok "> 完成 (done)" +} + +# start to set the global hook +hook(){ + if [ $1 == "" ]; then + print_error "缺少目录参数 (miss the directory param)" + exit 1 + fi + + projectDir=$1 + git config --global core.hooksPath ${projectDir}/include/hooks + chmod a+x ${projectDir}/include/hooks/commit-msg + chmod a+x ${projectDir}/include/hooks/post-checkout + chmod a+x ${projectDir}/include/hooks/post-merge + chmod a+x ${projectDir}/include/hooks/pre-commit + chmod a+x ${projectDir}/include/hooks/pre-push + + # 如果个别项目不需要使用全局的Hook, 可以在项目的根目录下重新配置git hooksPath: git config core.hooksPath .git/hooks + print_ok "hook successfully !" + print_warn "If your other projects don't need require the global Hooks, they can be reconfigured in the root directory of your other projects: git config core.hooksPath .git/hooks" +} + +# start to cancel the global hook +unhook(){ + git config --global core.hooksPath false +} + +# update your posture version +update_version(){ + currentDir=$(pwd) + cd $POSTUREPATH && git pull && cd $currentDir + # 判断是否拉取成功 + if [ $? -ne 0 ]; then + print_error "版本更新至最新版本失败 (Failed to update the version to the latest version)" + exit 1 + fi + print_ok "版本更新至最新版本成功 (update to latest version successfully)" +} + +# show status +status(){ + echo "The list of configuration" + echo "> lang = ${lang}" + echo "The list of states" + echo "> version = ${version}" +} + + COMMAND=$1 -if [ "${COMMAND}" == "hook" ]; then +if [ "${COMMAND}" == "adjust" ]; then + # requirement: cd to your project, then run cmd: posture adjust + adjust +elif [ "${COMMAND}" == "hook" ]; then # requirement: cd to your project, then run cmd: posture hook hook $POSTUREPATH elif [ "${COMMAND}" == "unhook" ]; then # requirement: cd to your project, then run cmd: posture unhook unhook -elif [ "${COMMAND}" == "adjust" ]; then - # requirement: cd to your project, then run cmd: posture adjust - adjust -elif [ "${COMMAND}" == "status" ]; then - status elif [ "${COMMAND}" == "update" ]; then update_version +elif [ "${COMMAND}" == "status" ]; then + status elif [ "${COMMAND}" == "help" ] || [ "${COMMAND}" == "" ]; then print_logo