Skip to content

Instantly share code, notes, and snippets.

@hobroker
Last active November 25, 2019 11:59
Show Gist options
  • Save hobroker/129a5ee98d56a8151ca8b9405507ea0d to your computer and use it in GitHub Desktop.
Save hobroker/129a5ee98d56a8151ca8b9405507ea0d to your computer and use it in GitHub Desktop.
git lazy commit
#!/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