-
-
Save CasperEngl/a83cb5fd9172ef5b6fb43846c9955424 to your computer and use it in GitHub Desktop.
OCM (Ollama Commit Message)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ollama_commit_message_prompt="Generate a concise git commit message written in present tense for the following code diff with the given specifications: 1: Commit message must be a maximum of 255 characters. 2: One line of text and no lists of changes. 3: Exclude anything unnecessary such as translation. Your entire response will be passed directly into git commit." | |
| ollama_commit_message_model="mistral" | |
| if [ -n "$OCM_COMMIT_MESSAGE_PROMPT" ]; then | |
| ollama_commit_message_prompt="$OCM_COMMIT_PROMPT" | |
| fi | |
| if [ -n "$OCM_COMMIT_MESSAGE_MODEL" ]; then | |
| ollama_commit_message_model="$OCM_COMMIT_MESSAGE_MODEL" | |
| fi | |
| git_diff=$(git diff --staged) | |
| if command -v ollama &>/dev/null; then | |
| if [ -n "$git_diff" ]; then | |
| commit_message=$(ollama run "$ollama_commit_message_model" "$ollama_commit_message_prompt $git_diff") | |
| echo -e "Commit message: \n\n $commit_message\n" | |
| read -p "Is the commit message correct? (Y/n) " confirm | |
| if [ "${confirm:-y}" == "y" ]; then | |
| git commit -m "$commit_message" | |
| else | |
| echo "Commit aborted." | |
| fi | |
| else | |
| echo "No changes to commit" | |
| fi | |
| else | |
| echo "Ollama is not installed. Please install it before running this script. https://ollama.com/" | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install
Place the file in your bin directory:
/usr/local/bin/ocmRun chmod to make the file executable:
chmod +x /usr/local/bin/ocmCustomize prompt
Add the following to your .bashrc or .zshrc.
Customize model
Pick any of the supported models from Ollama's model library: https://github.com/ollama/ollama?tab=readme-ov-file#model-library
Add the following to your .bashrc or .zshrc.