Skip to content

Instantly share code, notes, and snippets.

@kdxu
Created November 17, 2016 07:47
Show Gist options
  • Save kdxu/30f43478e8eb065cc4641bc80343da64 to your computer and use it in GitHub Desktop.
Save kdxu/30f43478e8eb065cc4641bc80343da64 to your computer and use it in GitHub Desktop.
#!/bin/sh
format=$(cat << EOS
Merge pray
feat sparkles
fix wrench
chore tea
refactor hammer
docs memo
style dress
perf runner
test eyes
format art
rm fire
bug bug
hotfix ambulance
docker whale
init tada
perform zap
add heavy_plus_sign
EOS
)
awk_script="$(echo "$format" | awk '{
if (NR != 1) printf "else "
print "if (match($1, /"$1"/)) print \":"$2":\"$0"
}')
else print \$0"
_command_exists() {
hash "$1" 2>/dev/null
}
msg=$(cat "$1")
if [ "$msg" != "" ] ; then
echo "$msg" | awk -F '(' "{ $awk_script }" > "$1"
else
if _command_exists peco ; then
type=$(echo "$format" | awk '{print ":"$2":"$1}' | peco)
scope=$(git status -s | awk '{
if (match($1, /A|M/)) {
print $2
}
}' | peco)
echo "$type($scope): " > "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment