mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Did a rebase merge from the old pull request #46 which we may close now. Yet it wasn't as simple as that in the end but all things have a resolve: Added 2 context type arguments to specify --local or --global. Refactored usage into functions te prevent duplication. Capable to view and append to both global gitignore as well as the .gitignore from the working folder. Supports all types of ignore patters including ! negated, comments as well as blank lines. Complete documentation including several examples.
51 lines
956 B
Bash
Executable file
51 lines
956 B
Bash
Executable file
#!/bin/bash
|
|
|
|
function show_contents {
|
|
test -f "$2" && echo "$1 gitignore: $2" && cat "$2"
|
|
}
|
|
|
|
function show_global {
|
|
show_contents Global `git config --global core.excludesfile`
|
|
}
|
|
|
|
function add_global {
|
|
add_patterns `git config --global core.excludesfile` "$@"
|
|
}
|
|
|
|
function show_local {
|
|
show_contents Local .gitignore
|
|
}
|
|
|
|
function add_local {
|
|
add_patterns .gitignore "$@"
|
|
}
|
|
|
|
function add_patterns {
|
|
echo "Adding pattern(s) to: $1"
|
|
for pattern in "${@:2}"; do
|
|
echo "... adding '$pattern'"
|
|
(test -f "$1" && test "$pattern" && grep -q "$pattern" "$1") || echo "$pattern" >> "$1"
|
|
done
|
|
}
|
|
|
|
if test $# -eq 0; then
|
|
show_global
|
|
echo "---------------------------------"
|
|
show_local
|
|
else
|
|
case "$1" in
|
|
-l|--local)
|
|
test $# -gt 1 && add_local "${@:2}" && echo
|
|
show_local
|
|
;;
|
|
-g|--global)
|
|
test $# -gt 1 && add_global "${@:2}" && echo
|
|
show_global
|
|
;;
|
|
*)
|
|
add_local "$@"
|
|
;;
|
|
esac
|
|
fi
|
|
|