├── PKGBUILD ├── LICENSE ├── README.md ├── commit └── install /PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Kunal Singh 2 | pkgname='git-commit' # name of the pacakge 3 | pkgver=0.2.1 # version of the application 4 | pkgrel=2 # version of the backage 5 | #epoch=1 # the newest package, next time set epoch to 2 (this is to ensure that this is the latest package, it default pkg ver comparsion not working) 6 | pkgdesc="Git commit simulator using Conventional Commits conventions" 7 | arch=('x86_64') 8 | url="https://github.com/KunalSin9h/git-commit.git" 9 | license=('MIT') 10 | depends=('gum') # Runtime dependency 11 | makedepends=('git') # build time dependency 12 | source=(git+https://github.com/KunalSin9h/git-commit.git) 13 | md5sums=('SKIP') 14 | 15 | package() { 16 | cd "$pkgname" 17 | install -Dm755 "commit" "$pkgdir/usr/bin/commit" 18 | install -Dm644 "README.md" "$pkgdir/usr/share/doc/$pkgname" 19 | install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE" 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Kunal Singh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # commit 2 | Git commit simulator using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) conventions. 3 | 4 | ![demo](https://user-images.githubusercontent.com/82411321/188562957-5b54ac73-ae61-43a0-9735-233bcb1405c3.gif) 5 | 6 | ## Installation 7 | ### ⚠️ ⚠️ Install [gum](https://github.com/charmbracelet/gum#installation) first. 8 | 9 |
10 | Install gum 11 | 12 | Use a package manager: 13 | 14 | ```bash 15 | # macOS or Linux 16 | brew install gum 17 | 18 | # Arch Linux (btw) 19 | pacman -S gum 20 | 21 | # Nix 22 | nix-env -iA nixpkgs.gum 23 | 24 | # Debian/Ubuntu 25 | echo 'deb [trusted=yes] https://repo.charm.sh/apt/ /' | sudo tee /etc/apt/sources.list.d/charm.list 26 | sudo apt update && sudo apt install gum 27 | 28 | # Fedora 29 | echo '[charm] 30 | name=Charm 31 | baseurl=https://repo.charm.sh/yum/ 32 | enabled=1 33 | gpgcheck=0' | sudo tee /etc/yum.repos.d/charm.repo 34 | sudo yum install gum 35 | ``` 36 | 37 | Or download it: 38 | 39 | * [Packages](https://github.com/charmbracelet/gum/releases) are available in Debian and RPM formats 40 | * [Binaries](https://github.com/charmbracelet/gum/releases) are available for Linux, macOS, and Windows 41 | 42 | Or just install it with `go`: 43 | 44 | ```bash 45 | go install github.com/charmbracelet/gum@latest 46 | ``` 47 |
48 | 49 |
50 | 51 | ### macOS x64 & Silicon, Linux x64, Windows Subsystem for Linux 52 | ```bash 53 | curl -s https://kunalsin9h.com/commit | bash 54 | ``` 55 | 56 | After Installing, add the following to your `.bashrc` file 57 | ```bash 58 | export COMMIT_INSTALL="$HOME/.commit" 59 | export PATH="$COMMIT_INSTALL/bin:$PATH" 60 | ``` 61 | 62 | ## From Arch User Repository (AUR) 63 | ```bash 64 | yay -S git-commit 65 | ``` 66 | 67 | ## Usage 68 | ```bash 69 | $ commit -h 70 | # or 71 | $ commit --help 72 | ``` 73 | 74 | Go to your project directory, stage your changes and run `commit` command. 75 | > Note: commit command will also prompt to stage your changes. 76 | ```bash 77 | $ cd my-project 78 | $ commit 79 | ``` 80 | 81 | ## Inspiration 82 | This project is inspired by [gum](https://github.com/charmbracelet/gum) 83 | 84 | ## License 85 | [MIT](https://github.com/KunalSin9h/commit/blob/master/LICENSE) 86 | 87 | -------------------------------------------------------------------------------- /commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reset 4 | Color_Off='' 5 | 6 | # Regular Colors 7 | Red='' 8 | Green='' 9 | Yellow='' 10 | Cyan='' 11 | Magenta='' 12 | Dim='' # White 13 | 14 | # Bold 15 | Bold_White='' 16 | Bold_Green='' 17 | 18 | if [[ -t 1 ]]; then 19 | # Reset 20 | Color_Off='\033[0m' # Text Reset 21 | 22 | # Regular Colors 23 | Red='\033[0;31m' # Red 24 | Green='\033[0;32m' # Green 25 | Yellow='\033[1;33m' # Yellow 26 | Cyan='\033[0;36m' 27 | Magenta='\033[1;35m' 28 | Dim='\033[0;2m' # White 29 | 30 | # Bold 31 | Bold_Green='\033[1;32m' # Bold Green 32 | Bold_White='\033[1m' # Bold White 33 | fi 34 | 35 | # commit intall path 36 | INSTALL="$HOME/.commit/bin/commit" 37 | 38 | # Current Version of commit 39 | CURRENT_RELEASE="v0.2.1" 40 | 41 | # get latest release from github 42 | LATEST_RELEASE=$(curl -s https://api.github.com/repos/KunalSin9h/git-commit/releases/latest | grep "tag_name" | cut -d '"' -f 4) 43 | 44 | # upgrate to latest version on --upgrade 45 | if [[ $1 == "--upgrade" || $1 == "-u" ]]; then 46 | if [[ $CURRENT_RELEASE == $LATEST_RELEASE ]]; then 47 | echo -e "${Bold_White}You are already using the latest version of commit${Color_Off} (Which is $CURRENT_RELEASE)" 48 | else 49 | echo -e "${Bold_White}Upgrading${Color_Off} commit ($CURRENT_RELEASE -> $LATEST_RELEASE)" 50 | if [[ $(which commit) == "/usr/bin/commit" ]]; then 51 | echo -e "${Din}You need ${Bold_White}sudo${Color_Off} for this ${Color_Off}" 52 | curl -s https://raw.githubusercontent.com/KunalSin9h/git-commit/$LATEST_RELEASE/commit > "/usr/bin/commit" && echo -e "${Bold_Green}Successfully Upgraded${Color_Off}" 53 | else 54 | curl -s https://raw.githubusercontent.com/KunalSin9h/git-commit/$LATEST_RELEASE/commit > $INSTALL && echo -e "${Bold_Green}Successfully Upgraded${Color_Off}" 55 | fi 56 | fi 57 | exit 0 58 | fi 59 | 60 | if [[ $1 == "--version" || $1 == "-v" ]]; then 61 | echo -e "${Bold_White}commit${Color_Off} $CURRENT_RELEASE" 62 | exit 0 63 | fi 64 | 65 | if [[ $1 == "--help" || $1 == "-h" ]]; then 66 | echo -e "${Bold_White}commit${Color_Off} $CURRENT_RELEASE" 67 | echo -e "${Bold_White}Usage:${Color_Off} commit [options]" 68 | echo -e "${Bold_White}Options:${Color_Off}" 69 | echo -e " -h, --help\t\t\tShow this help message" 70 | echo -e " -v, --version\t\t\tShow commit version" 71 | echo -e " -u, --upgrade\t\t\tUpgrade commit to latest version" 72 | exit 0 73 | fi 74 | 75 | if [[ $CURRENT_RELEASE != $LATEST_RELEASE ]]; then 76 | echo "Update available ($CURRENT_RELEASE -> $LATEST_RELEASE)" 77 | echo -e "${Bold_White}commit --upgrade${Color_Off} to install latest version" 78 | fi 79 | 80 | SIGNED_OFF_BY="" 81 | 82 | gum confirm "Do you want to stage changes? (git add .)" --selected.background="80" && git add . && echo -e "${Bold_Green}Changes staged${Color_Off}" 83 | 84 | gum confirm "Do you want to add Signed-off-by in commit body?" --selected.background="80" && SIGNED_OFF_BY="-s" 85 | 86 | COMMIT_TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert" --cursor.foreground "#5fd7d7") 87 | SCOPE=$(gum input --cursor.foreground "#5fd7d7" --placeholder "scope") 88 | 89 | # Since the scope is optional, wrap it in parentheses if it has a value. 90 | test -n "$SCOPE" && SCOPE="($SCOPE)" 91 | 92 | # Pre-populate the input with the type(scope): so that the user may change it 93 | SUMMARY=$(gum input --cursor.foreground "#5fd7d7" --value "$COMMIT_TYPE$SCOPE: " --placeholder "Summary of this change") 94 | DESCRIPTION=$(gum write --cursor.foreground "#5fd7d7" --placeholder "Details of this change (CTRL+D to finish)") 95 | 96 | # Commit these changes 97 | gum confirm "Commit changes?" --selected.background="80" && git commit $SIGNED_OFF_BY -m "$SUMMARY" -m "$DESCRIPTION" && echo -e "${Bold_Green}Successfully Commit Changes${Color_Off}" 98 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Reset 4 | Color_Off='' 5 | 6 | # Regular Colors 7 | Red='' 8 | Green='' 9 | Yellow='' 10 | Cyan='' 11 | Magenta='' 12 | Dim='' # White 13 | 14 | # Bold 15 | Bold_White='' 16 | Bold_Green='' 17 | 18 | if [[ -t 1 ]]; then 19 | # Reset 20 | Color_Off='\033[0m' # Text Reset 21 | 22 | # Regular Colors 23 | Red='\033[0;31m' # Red 24 | Green='\033[0;32m' # Green 25 | Yellow='\033[1;33m' # Yellow 26 | Cyan='\033[0;36m' 27 | Magenta='\033[1;35m' 28 | Dim='\033[0;2m' # White 29 | 30 | # Bold 31 | Bold_Green='\033[1;32m' # Bold Green 32 | Bold_White='\033[1m' # Bold White 33 | fi 34 | 35 | bold_success() { 36 | echo -e "${Bold_Green}$@ ${Color_Off}" 37 | } 38 | 39 | info() { 40 | echo -e "${Dim}$@ ${Color_Off}" 41 | } 42 | 43 | info_bold() { 44 | echo -e "${Bold_White}$@ ${Color_Off}" 45 | } 46 | 47 | error() { 48 | echo -e "${Red}error${Color_Off}:" "$@" >&2 49 | exit 1 50 | } 51 | 52 | success() { 53 | echo -e "${Bold_Breen}$@ ${Color_Off}" 54 | } 55 | 56 | # check is curl installed or not 57 | if ! command -v curl &> /dev/null 58 | then 59 | error "commit uses curl for downloading files, please install curl and try again" 60 | fi 61 | 62 | bold_success 63 | bold_success █▀▀ █▀█ █▀▄▀█ █▀▄▀█ █ ▀█▀ 64 | bold_success █▄▄ █▄█ █░▀░█ █░▀░█ █ ░█░ 65 | bold_success 66 | 67 | echo -e "${Yellow}Commit${Color_Off} helps in better git experience and maintain proper commit messages." 68 | 69 | if ! [ -x "$(command -v gum)" ]; then 70 | echo "" 71 | echo >&2 -e "${Red}Error${Color_Off}: ${Bold_White}gum${Color_Off} is not installed." 72 | echo >&2 -e "Commit uses gum for styling prompts, ${Magenta}make sure you have installed gum${Color_Off} before proceeding. ${Cyan}https://github.com/charmbracelet/gum#installation${Color_Off}" 73 | exit 1 74 | fi 75 | 76 | echo 77 | info "Installing commit..." 78 | 79 | commit_uri=https://raw.githubusercontent.com/KunalSin9h/git-commit/master/commit 80 | 81 | # get latest release from github 82 | LATEST_RELEASE=$(curl -s https://api.github.com/repos/KunalSin9h/git-commit/releases/latest | grep "tag_name" | cut -d '"' -f 4) 83 | 84 | install_env=COMMIT_INSTALL 85 | bin_env=\$$install_env/bin 86 | 87 | install_dir=${!install_env:-$HOME/.commit} 88 | bin_dir=$install_dir/bin 89 | sh=$bin_dir/commit 90 | 91 | if [[ ! -d $bin_dir ]]; then 92 | mkdir -p "$bin_dir" || 93 | error -e "${Red}Failed${Color_Off} to create install directory \"$bin_dir\"" 94 | fi 95 | 96 | curl -fsSL --fail --location --output "$sh" "$commit_uri" || 97 | error "Failed to download commit from \"$commit_uri\"" 98 | 99 | gum spin --spinner dot --title "Downloading commit..." --spinner.foreground="80" -- sleep 5 && echo -e "commit version $LATEST_RELEASE downloaded. ${Cyan}https://github.com/KunalSin9h/git-commit${Color_Off}" 100 | 101 | gum spin --spinner dot --title "Setting Up..." --spinner.foreground="80" -- sleep 3 102 | 103 | chmod +x "$sh" || 104 | error 'Failed to set permissions on commit executable' 105 | 106 | tildify() { 107 | if [[ $1 = $HOME/* ]]; then 108 | local replacement=\~/ 109 | 110 | echo "${1/$HOME\//$replacement}" 111 | else 112 | echo "$1" 113 | fi 114 | } 115 | 116 | echo 117 | success "commit was installed successfully to $Bold_Green$(tildify "$sh")" 118 | 119 | refresh_command='' 120 | 121 | tilde_bin_dir=$(tildify "$bin_dir") 122 | quoted_install_dir=\"${install_dir//\"/\\\"}\" 123 | 124 | if [[ $quoted_install_dir = \"$HOME/* ]]; then 125 | quoted_install_dir=${quoted_install_dir/$HOME\//\$HOME/} 126 | fi 127 | 128 | echo 129 | 130 | case $(basename "$SHELL") in 131 | fish) 132 | commands=( 133 | "set --export $install_env $quoted_install_dir" 134 | "set --export PATH $bin_env \$PATH" 135 | ) 136 | 137 | fish_config=$HOME/.config/fish/config.fish 138 | tilde_fish_config=$(tildify "$fish_config") 139 | 140 | if [[ -w $fish_config ]]; then 141 | { 142 | echo -e '\n# commit' 143 | 144 | for command in "${commands[@]}"; do 145 | echo "$command" 146 | done 147 | } >>"$fish_config" 148 | 149 | info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_fish_config\"" 150 | 151 | refresh_command="source $tilde_fish_config" 152 | else 153 | echo "Manually add the directory to $tilde_fish_config (or similar):" 154 | 155 | for command in "${commands[@]}"; do 156 | info_bold " $command" 157 | done 158 | fi 159 | 160 | ;; 161 | zsh) 162 | commands=( 163 | "export $install_env=$quoted_install_dir" 164 | "export PATH=\"$bin_env:\$PATH\"" 165 | ) 166 | 167 | zsh_config=$HOME/.zshrc 168 | tilde_zsh_config=$(tildify "$zsh_config") 169 | 170 | if [[ -w $zsh_config ]]; then 171 | { 172 | echo -e '\n# commit' 173 | 174 | for command in "${commands[@]}"; do 175 | echo "$command" 176 | done 177 | } >>"$zsh_config" 178 | 179 | info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_zsh_config\"" 180 | 181 | refresh_command="exec $SHELL" 182 | else 183 | echo "Manually add the directory to $tilde_zsh_config (or similar):" 184 | 185 | for command in "${commands[@]}"; do 186 | info_bold " $command" 187 | done 188 | fi 189 | ;; 190 | *) 191 | echo -e "Manually add the directory to ${Yellow}~/.bashrc${Color_Off} (or similar):" 192 | info_bold " export $install_env=$quoted_install_dir" 193 | info_bold " export PATH=\"$bin_env:\$PATH\"" 194 | ;; 195 | esac 196 | 197 | echo 198 | echo -e "To get started, go to your project folder and type ${Yellow}commit${Color_Off} to commit changes." 199 | echo 200 | 201 | if [[ $refresh_command ]]; then 202 | info_bold " $refresh_command" 203 | fi 204 | --------------------------------------------------------------------------------