From a94848915659f84beb2797ff1564822b7df4ff35 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Fri, 30 Oct 2015 03:28:32 -0400 Subject: [PATCH] add git-ignore-add function to git module --- modules/git/README.md | 1 + modules/git/functions/git-ignore-add | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 modules/git/functions/git-ignore-add 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