Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 02e07cc41b
Fetching contributors…

Cannot retrieve contributors at this time

executable file 173 lines (151 sloc) 4.17 kB
#!/bin/sh
#
# Script for easily accessing gitignore boilerplates from
# https://github.com/github/gitignore
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
#
# Change log
# v1.0 1-May-2012 First public release
remote_repo=https://github.com/github/gitignore.git
local_repo=$HOME/.gitignore-boilerplates
version() {
echo "$(basename $0) 1.0 by Simon Whitaker <simon@goosoftware.co.uk>"
echo "https://github.com/simonwhitaker/gitignore-boilerplates"
}
usage() {
version
cat << EOF >&2
Fetches gitignore boilerplates from github.com/github/gitignore
Usage:
$(basename $0) [options]
$(basename $0) [boilerplate boilerplate...]
Example:
$(basename $0) Python TextMate >> .gitignore
Options:
-l, --list List available boilerplates
-u, --upgrade Upgrade list of available boilerplates
-h, --help Display this help text
-v, --version Display current script version
EOF
}
clone() {
echo "Cloning $remote_repo to $local_repo"
git clone "$remote_repo" "$local_repo"
}
init() {
if [ ! -e "$local_repo/.git" ]; then
clone
fi
}
list() {
init
echo "=== Languages ==="
echo
for path in $(ls "$local_repo"/*.gitignore | sort -f); do
filename=$(basename $path)
echo "${filename%.*}"
done
echo
echo "=== Global ==="
echo
for path in $(ls "$local_repo"/Global/*.gitignore | sort -f); do
filename=$(basename $path)
echo "${filename%.*}"
done
}
upgrade() {
if [ ! -e "$local_repo/.git" ]; then
clone
else
cd "$local_repo"
git pull origin master
fi
}
dump() {
init
language_file="$local_repo/$1.gitignore"
global_file="$local_repo/Global/$1.gitignore"
if [ -e "$language_file" ]; then
echo "### $language_file"
echo
cat "$language_file"
echo
echo
elif [ -e "$global_file" ]; then
echo "### $global_file"
echo
cat "$global_file"
echo
echo
else
echo "Unknown argument: $1" >&2
fi
}
# --- Main entry point ----------------------
if [ $# -eq 0 ]; then
usage
exit 0
fi
# Sanity check command-line options. We want either
# options like -l or arguments like Python, but not
# both
has_opts=0
has_args=0
for opt in $@; do
if [ $( echo $opt | cut -c1) = "-" ]; then
has_opts=1
else
has_args=1
fi
done
if [ $has_opts -eq 1 -a $has_args -eq 1 ]; then
usage
exit 1
fi
# Parse comand-line options
while [ $# -gt 0 ]; do
case $1 in
-v | --version )
version
exit 1
;;
-l | --list )
list
;;
-u | --upgrade )
upgrade
;;
-h | --help )
usage
exit 1
;;
* ) # default case
dump $1
;;
esac
shift
done
Jump to Line
Something went wrong with that request. Please try again.