forked from intentionally-left-nil/github-pair-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·59 lines (50 loc) · 1.52 KB
/
setup.sh
File metadata and controls
executable file
·59 lines (50 loc) · 1.52 KB
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
#! /bin/bash
set -euo pipefail
function _require()
{
if ! command -v $1 &> /dev/null; then
echo "This program depends on $1 to be installed"
echo "You can use your package manager (eg brew install $1) to install it"
exit 1
fi
}
function _addToStartup()
{
local path=$1
if [ -f $path ]; then
if grep -q 'pair_with.sh' "$path"; then
echo "pair_with_sh is already added to $path"
else
echo "Adding the pair_with script to $path"
echo "[ -f /usr/local/bin/pair_with.sh ] && . /usr/local/bin/pair_with.sh" >> $path
fi
fi
}
function setup()
{
# Make sure dependencies are installed
_require "jq"
_require "curl"
_require "git"
# Set the core.hooksPath in git
if ! git config --global --get core.hooksPath; then
echo "There is no global git hook path, creating one at ${HOME}/.git-hooks"
mkdir "${HOME}/.git-hooks"
git config --global core.hooksPath ${HOME}/.git-hooks
fi
local hookpath=`git config --global --get core.hooksPath`
# Make sure there is no existing commit-msg
if [ -f $hookpath/commit-msg ]; then
echo "The file $hookpath/commit-msg already exists. This script refuses to overwrite it"
echo "Please delete the file and run this command again"
exit 1
fi
local dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Move the scripts to /usr/local/bin
cp $dir/pair_with.sh /usr/local/bin
# Copy the commit-msg to the hooks path
cp $dir/commit-msg $hookpath
_addToStartup "${HOME}/.bashrc"
_addToStartup "${HOME}/.zshrc"
}
setup