36 lines
873 B
Nix
36 lines
873 B
Nix
{ writeShellScriptBin
|
|
|
|
# Dependencies
|
|
, git
|
|
, moreutils
|
|
}:
|
|
|
|
writeShellScriptBin "add-words" ''
|
|
set -Eeuo pipefail
|
|
|
|
cd "/home/ak/src/configuration"
|
|
|
|
message='Update spell check word list'
|
|
txt='common/resources/words.txt'
|
|
|
|
if [[ -n "$(${git}/bin/git status --porcelain "$txt")" ]]; then
|
|
echo "Error: Existing uncommitted changes to $txt" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n "$(${git}/bin/git diff --cached --name-only)" ]]; then
|
|
echo "Error: Existing staged changes" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s\n' "$@" | sort "$txt" - | uniq | ${moreutils}/bin/sponge "$txt"
|
|
${git}/bin/git add "$txt"
|
|
|
|
if [[ "$(${git}/bin/git log -1 --pretty='%s')" == "$message" ]] && ! ${git}/bin/git merge-base --is-ancestor 'HEAD' '@{u}'; then
|
|
${git}/bin/git commit --amend --no-edit
|
|
else
|
|
${git}/bin/git commit --message "$message"
|
|
fi
|
|
|
|
${git}/bin/git show HEAD
|
|
''
|