- Add .config/git/config + Define aliases + Configure default behavior in various situations + Add user information with signing key - Add .config/git/commit_msg_template.txt - Add .config/git/ignore - Integrate `git` aliases into the shell
46 lines
1 KiB
Shell
Executable file
46 lines
1 KiB
Shell
Executable file
#!/bin/sh
|
|
|
|
# Remove all files ignored by `git`, except the ones listed in $KEEP below
|
|
#
|
|
# `git clean` does not accept "-e" together with "-X",
|
|
# so the files to be kept are moved aside and then restored
|
|
#
|
|
# Usage: git clean-ignored [<git clean options>]
|
|
|
|
set -eu
|
|
|
|
|
|
# Keep this list in sync with the other two copies:
|
|
# - the "-e" flags of `clean-untracked` in ~/.config/git/config
|
|
# - the preview in ~/.local/bin/git-clean-all
|
|
KEEP=".env .python-version"
|
|
|
|
SUFFIX=".git-clean-ignored.bak"
|
|
|
|
|
|
# `git` runs scripts on the `$PATH` in the current directory,
|
|
# whereas it runs "!" aliases at the top level of the repository
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
|
|
_restore() {
|
|
for _file in $KEEP; do
|
|
if [ -f "$_file$SUFFIX" ]; then
|
|
mv "$_file$SUFFIX" "$_file"
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
# Restore the kept files even if `git clean` fails or the user aborts
|
|
trap _restore EXIT HUP INT TERM
|
|
|
|
|
|
for _file in $KEEP; do
|
|
if [ -f "$_file" ]; then
|
|
mv "$_file" "$_file$SUFFIX"
|
|
fi
|
|
done
|
|
|
|
|
|
git clean -X -d -f "$@"
|