-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·65 lines (52 loc) · 1.24 KB
/
install
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
#!/usr/bin/env bash
# Inspired by the installation mechanism for fzf:
# https://github.com/junegunn/fzf/
INSTALL_PATH=~/.git-tree
# For now, this assumes that git-tree has already been built.
append_line() {
set -e
local update line file pat lno
update="$1"
line="$2"
file="$3"
pat="${4:-}"
lno=""
echo "Update $file:"
echo " - $line"
if [ -f "$file" ]; then
if [ $# -lt 4 ]; then
lno=$(\grep -nF "$line" "$file" | sed 's/:.*//' | tr '\n' ' ')
else
lno=$(\grep -nF "$pat" "$file" | sed 's/:.*//' | tr '\n' ' ')
fi
fi
if [ -n "$lno" ]; then
echo " - Already exists: line #$lno"
else
if [ $update -eq 1 ]; then
[ -f "$file" ] && echo "$line" >> "$file"
echo " + Added"
else
echo " ~ Skipped"
fi
fi
echo
set +e
}
add_gittreerc() {
cp ${INSTALL_PATH}/.gittreerc ~/.gittreerc
}
add_source_to_bashrc() {
append_line 1 "[ -f ~/.gittreerc ] && source ~/.gittreerc" ~/.bashrc "~/.gittreerc"
}
print_finish() {
cat << EOF
Finished. Restart your shell or reload config file.
source ~/.bashrc # bash
Use uninstall script to remove git-tree.
For more information, see: https://github.com/acamadeo/git-tree
EOF
}
add_gittreerc
add_source_to_bashrc
print_finish