Last active
November 25, 2019 11:59
-
-
Save hobroker/129a5ee98d56a8151ca8b9405507ea0d to your computer and use it in GitHub Desktop.
git lazy commit
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
#!/usr/bin/env bash | |
# Usage: | |
# $ glc refactor | |
set -e | |
# use any characters besides: [],; | |
_types="[π¨],[style],[improve structure / format of the code] | |
[β‘οΈ],[perf],[improve performance] | |
[π₯],[prune],[remove code or files] | |
[π],[fix],[fix a bug] | |
[π],[quickfix],[critical hotfix] | |
[β¨],[feature],[introduce new features] | |
[π],[docs],[write docs;Document source code] | |
[π],[deploy],[deploy stuff] | |
[π],[ui],[update the UI and style files] | |
[π],[init],[initial commit] | |
[β ],[test],[add tests] | |
[π],[security],[fix security issues] | |
[π],[release],[add release / version tags] | |
[π¨],[lint],[fix linter warnings;make linter happy] | |
[π§],[wip],[work in progress] | |
[π·],[ci],[add CI;fix CI] | |
[π],[analytics],[add analytics or tracking code] | |
[β»οΈ],[refactoring],[refactor code] | |
[π³],[docker],[change Docker config] | |
[β],[dep-add],[add dependencies] | |
[β],[dep-rm],[remove dependencies] | |
[β¬οΈ],[downgrade],[downgrade dependencies] | |
[β¬οΈ],[upgrade],[upgrade dependencies] | |
[π],[lock],[update lock file] | |
[π§],[config],[change configuration files] | |
[π],[i18n],[internationalization and localization] | |
[βοΈ],[typo],[fix typos] | |
[π©],[poo],[write bad code that needs to be improved] | |
[βͺ],[revert],[revert changes;going back] | |
[π],[merge],[merge branches] | |
[π],[mv],[move or rename files] | |
[π],[license],[change license] | |
[π₯],[breaking],[introduce breaking changes] | |
[π±],[assets],[change assets] | |
[π],[review],[update code due to code review changes] | |
[π¬],[texts],[update text and literals] | |
[π],[db],[perform database related changes] | |
[πΈ],[ux],[improve user experience;improve UX] | |
[π],[architecture],[make architectural changes] | |
[π±],[responsive],[change responsive design] | |
[π€‘],[mock],[mock things] | |
[π₯],[egg],[add an easter egg] | |
[β],[experiment],[experiment new things] | |
[π·οΈ],[types],[change types] | |
[π±],[seed],[change seeds] | |
[π«],[animation],[change animations and transitions]" | |
require_value() { | |
if [[ -z "$@" ]] | |
then | |
exit 1 | |
fi | |
} | |
search() { | |
local result=$(echo "$1" | fzf --preview '' --height 7 --reverse) | |
require_value "$result" | |
echo "$result" | |
} | |
glc() { | |
# searches fuzzily from types and trims "[" & "]" | |
local item=$(search "$_types" | sed 's/^\[\(.*\)\]$/\1/') | |
# splits $item into $array by "],[" | |
IFS='],[' read -r -a array <<< "$item" | |
local emoji="${array[0]}" | |
local messages="${array[6]}" | |
if [[ ! -z "$@" ]] | |
then | |
messages="$@;$messages" | |
fi | |
# replaces ";" to "\n" | |
messages=$(echo "$messages" | sed -e $'s/;/\\\n/g') | |
# searches fuzzily from messages | |
local message=$(search "$messages") | |
local commit_command="git commit -m \"$emoji $message\"" | |
local commands="commit_command | |
$git commit --amend -m \"$emoji $message\" | |
$commit_command && git push origin HEAD" | |
# searches fuzzily from commands | |
local command=$(search "$commands") | |
echo "${command}" | |
eval "${command}" | |
} | |
glc $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment