Skip to content

Commit bc7ee88

Browse files
authored
Merge pull request #2 from lamhaison/develop
[Add] - function for suggestion when commit code
2 parents e1cf7e3 + 5f82f81 commit bc7ee88

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,11 @@ echo "source /opt/lamhaison-tools/helpful-commandlines/main.sh" >> ~/.bashrc
4444
# How to search commandline
4545
```
4646
Ctrl + H or lhs_help_helpful
47+
48+
```
49+
50+
# How to enable git commit suggestions
51+
```
52+
Option + gc or lhs_git_commit_suggestions | peco
4753
```
4854

main.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ if [[ "${LHS_BIND_KEY}" = "True" ]]; then
8080

8181
zle -N lhs_help_all
8282
bindkey '^h' lhs_help_all
83+
84+
# Hot key for git commit suggestions
85+
zle -N lhs_git_commit_suggestions_with_hint
86+
# Hotkey: Option + gc
87+
bindkey '©ç' lhs_git_commit_suggestions_with_hint
8388
fi

services/git.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,50 @@ function lhs_git_scan_secrets() {
1212
echo "\033[31m Scan recursive \033[0m"
1313
docker run --rm -v $(pwd):/repository:ro ${image_name} git secrets --scan -r /repository
1414
}
15+
16+
function lhs_git_commit_suggestions() {
17+
18+
# More instruction - https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/
19+
# - https://chiamakaikeanyi.dev/how-to-write-good-git-commit-messages/
20+
# Set default git commit message - https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
21+
cat <<-__EOF__
22+
git commit -m "[Add] - Your add description"
23+
git commit -m "[Update] - Your update description"
24+
git commit -m "[Remove] - remove somethings such as functions, temp file, ..."
25+
git commit -m "[Feat] – a new feature is introduced with the changes"
26+
git commit -m "[Fix] - a bug fix has occurred"
27+
git commit -m "[Chore] – for updating dependencies"
28+
git commit -m "[Refactor] - refactored code that neither fixes a bug nor adds a feature"
29+
git commit -m "[Docs] - updates to documentation such as a the README or other markdown files"
30+
git commit -m "[Style] - related to code formatting such as white-space, missing semi-colons, and so on"
31+
git commit -m "[Test] - including new or correcting previous tests"
32+
git commit -m "[Perf] – performance improvements"
33+
git commit -m "[CiCd] - continuous integration and continuous delivery related"
34+
git commit -m "[Build] – changes that affect the build system or external dependencies"
35+
git commit -m "[Revert] - reverts a previous commit"
36+
git commit -m "[Release] - Your Release description (Comment for the PR)"
37+
38+
+ Example(You have to add git commit -m "" manually):
39+
Ex: git commit -m "[Feat] - improve performance with lazy load implementation for images"
40+
Ex: git commit -m "[Chore] - update npm dependency to latest version"
41+
Ex: git commit -m "[Fix] - bug preventing users from submitting the subscribe form"
42+
Ex: git commit -m "[Update] - incorrect client phone number within footer body per client request"
43+
Ex: git commit -m "[Refactor] - to refactor function names"
44+
Ex: git commit -m "[Chore] - to fix typo"
45+
46+
__EOF__
47+
}
48+
49+
function lhs_git_commit_suggestions_with_hint() {
50+
local lhs_input=$(
51+
lhs_git_commit_suggestions | peco --query "$LBUFFER" --prompt "Git commit suggestions >"
52+
)
53+
54+
# To check it is example.
55+
if [[ $lhs_input = Ex:* ]]; then
56+
BUFFER=$(echo "${lhs_input}" | awk -F "Ex:" '{print $2}')
57+
else
58+
BUFFER=${lhs_input}
59+
fi
60+
CURSOR=$#BUFFER
61+
}

0 commit comments

Comments
 (0)