Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
executable file 154 lines (132 sloc) 3.179 kB
#!/bin/sh
#
# Script for easily accessing gitignore boilerplates from
# https://github.com/github/gitignore
#
# Change log
# v1.0 1-May-2012 First public release
remote_repo=https://github.com/github/gitignore.git
local_repo=$HOME/.gitignore-boilerplates
current_repo_rev=$(git -C $local_repo rev-parse HEAD)
remote_web_root=https://raw.github.com/github/gitignore/$current_repo_rev
version() {
echo "$(basename $0) 1.0.4 by Simon Whitaker <sw@netcetera.org>"
echo "https://github.com/simonwhitaker/gibo"
}
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() {
if [ $1 -a $1 = '--silently' ]; then
git clone -q "$remote_repo" "$local_repo"
else
echo "Cloning $remote_repo to $local_repo"
git clone "$remote_repo" "$local_repo"
fi
}
init() {
if [ ! -e "$local_repo/.git" ]; then
clone $1
fi
}
list() {
init
echo "=== Languages ==="
echo
for path in $(ls "$local_repo"/*.gitignore | sort -f); do
filename=$(basename $path)
echo "${filename%.*}"
done | column
echo
echo "=== Global ==="
echo
for path in $(ls "$local_repo"/Global/*.gitignore | sort -f); do
filename=$(basename $path)
echo "${filename%.*}"
done | column
}
upgrade() {
if [ ! -e "$local_repo/.git" ]; then
clone
else
cd "$local_repo"
git pull origin master
fi
}
dump() {
init --silently
language_file="$local_repo/$1.gitignore"
global_file="$local_repo/Global/$1.gitignore"
if [ -e "$language_file" ]; then
echo "### $remote_web_root/$1.gitignore"
echo
cat "$language_file"
echo
echo
elif [ -e "$global_file" ]; then
echo "### $remote_web_root/Global/$1.gitignore"
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.