dotfiles/git/hooks/prepare-commit-msg

33 lines
1.1 KiB
Text
Raw Normal View History

2024-02-03 12:13:00 -08:00
#!/bin/bash
###############################################################################
## Title: gitmoji-fuzzy-hook-init
## Brief: It opens a fuzzy searcher with gitmojis, to allow the git commit
## caller to select one. For git commit visual mode
## it adds a description of the selected emoji.
## Args:
## $1: File of the commit message
## $2: Commit type
## $3: Commit Hash
##
## Returns:
## Prepends a selectable gitmoji to the git commit message.
##
## Source: https://gitlab.com/raabf/gitmoji-fuzzy-hook
## Author: Fabian Raab <fabian@raab.link>
## Dependencies: gitmoji-fuzzy-hook
###############################################################################
[ -t 1 ] # checks if this script is called from a terminal
emoji="$(/Users/marley/dotfiles/git/gitmoji-fuzzy-hook/bin/gitmoji-fuzzy-hook-exec.sh $? $@)"
2024-02-03 12:13:00 -08:00
msg_file="$1"
msg="$(cat "$msg_file")"
# Do here whatever you want with the commit message before prepending the emoji
# to it and writing the message to the commit file.
if [ ! -z "${emoji}" ]; then # surpress the space if there is no emoji
2024-02-03 12:13:00 -08:00
msg="${emoji} ${msg}"
fi
echo -e "$msg" >"$msg_file"