diff --git a/modules/git/README.md b/modules/git/README.md index c2d0449c..50bb1f09 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -231,6 +231,7 @@ Functions - `git-hub-shorten-url` shortens GitHub URLs. - `git-info` exposes repository information via the `$git_info` associative array. + - `git-ignore-add` adds any passed paramaters to the root's .gitignore. - `git-root` displays the path to the working tree root. - `git-stash-clear-interactive` asks for confirmation before clearing the stash. - `git-stash-dropped` lists dropped stashed states. diff --git a/modules/git/functions/git-ignore-add b/modules/git/functions/git-ignore-add new file mode 100644 index 00000000..53be08a5 --- /dev/null +++ b/modules/git/functions/git-ignore-add @@ -0,0 +1,17 @@ +# +# Adds files passed as parameters to .gitignore in project root +# +# Authors: +# Matt Hamilton +# + +# make sure we have a git-root +if ! git-root &> /dev/null; then + print 'not in a git repository' >&2 + return 1 +fi + +# we are in a git repository. add parameters to .gitignore +for file in "$@" do + print "$file" >>! $(git-root)/.gitignore +done