-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgithub-init
executable file
·111 lines (81 loc) · 2.46 KB
/
github-init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#/bin/sh
set -euf
## Tracking
program_command="github-init"
program_version="4.0.0"
program_updated="2018-05-22"
program_license="GPL"
program_contact="Joel Parker Henderson ([email protected])"
## Help
help(){
cat << CAT
github-init: run git-init then clone any files in a config directory.
Syntax:
github-init
Typical result:
$ git init
$ rsync -av ~/.github-start/ .
Implementation:
* If necessary commands are missing, then exit.
* If the directory `.git` already exists, then do not init.
* Sync files yet do not overwrite any existing files.
* Add any GitHub special files as needed.
GitHub special files:
* README.md
* LICENSE.md
* CONTRIBUTING.md
* CODE_OF_CONDUCT.md
* ISSUE_TEMPLATE.md
* PULL_REQUEST_TEMPLATE.md
* CODEOWNERS
Conventions:
* This script creates Markdown files.
* Headlines use first letter uppercase, not every-word uppercase.
* The CODEOWNERS special file uses its own syntax, not Markdown.
Known issues:
* None
Future goals:
* Enable configuration of Markdown vs. ASCIIDOC vs. text.
CAT
}
if [ "$#" -eq 1 ]; then
case "$1" in
-h|--help)
help; exit 0
;;
esac
fi
## Toolkit
out() { printf %s\\n "$*" ; }
err() { >&2 printf %s\\n "$*" ; }
die() { err $(log) "$*" ; exit 255 ; }
cmd() { command -v $1 >/dev/null 2>&1 ; }
## Functions
# Configuration
config_dir() { out "${XDG_CONFIG_HOME:-$HOME/.config/$program_command}" ; }
# Preflight
cmd_git { cmd "git" || die "Command missing: git" }
cmd_rsync { cmd "rsync" || die "Command missing: rsync" }
# Initialize
git_init() { -e .git || git init ; }
clone_files { rsync -av --ignore-existing "$(config_dir)/" . || die "Cannot rsync" ; }
# Add GitHub special files as needed
add_readme { -e README.md || out "# Read me" > README.md ; }
add_license { -e LICENSE.md || out "# Licence" > LICENSE.md ; }
add_contributing { -e CONTRIBUTING.md || out "# Contributing" > CONTRIBUTING.md ; }
add_code_of_conduct { -e CODE_OF_CONDUCT.md || out "# Code of conduct" > CODE_OF_CONDUCT.md ; }
add_code_owners { -e CODEOWNERS || out "* [email protected]" > CODEOWNERS ; }
add_issue_template { -e ISSUE_TEMPLATE.md || out "# Issue template" > ISSUE_TEMPLATE.md ; }
add_pull_request_template { -e PULL_REQUEST_TEMPLATE.md || out "# Pull request template" > PULL_REQUEST_TEMPLATE.md ; }
## Main
cmd_git
cmd_rysnc
git_init
clone_files
add_readme
add_license
add_contributing
add_code_of_conduct
add_code_owners
add_issue_template
add_pull_request_template