-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc-install
78 lines (62 loc) · 1.85 KB
/
bashrc-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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# git-bashrc install script
#
# To install:
#
# $ source bashrc-install [--bashrc | --bash_profile | --profile] [--configure-git | --no-configure-git]
#
# By default, this script will install to ~/.bash_profile, unless it looks like
# ~/.bash_profile sources ~/.bashrc (recommended), in which case we install to ~/.bashrc.
# You may stipulate the exact install location by providing the appropriate flag.
#
# Get the path to the directory this script was ran from
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Presume that we will install to .bash_profile. If it looks like
# .bash_profile is including .bashrc, then we will install to .bashrc.
INSTALL_TO=".bash_profile"
if [ ! -f "$INSTALL_TO" ] || grep -q bashrc "$HOME/$INSTALL_TO" ; then
INSTALL_TO=".bashrc"
fi
# TODO: Maybe check to see if git defaults have already been changed,
# and default to false if so?
CONFIGURE_GIT=true
# Parse options
while [ $# -gt 0 ] ; do
option=$1
shift
case "$option" in
--bashrc )
INSTALL_TO=".bashrc"
;;
--bash_profile )
INSTALL_TO=".bash_profile"
;;
--profile )
INSTALL_TO=".profile"
;;
--configure-git )
CONFIGURE_GIT=true
;;
--no-configure-git )
CONFIGURE_GIT=false
;;
esac
done
# Run the configure-git script
if $CONFIGURE_GIT ; then
source "$SCRIPT_DIR/configure-git"
fi
# If it looks like the git-bashrc file is already being sourced, then exit.
if grep -q git-bashrc "$HOME/$INSTALL_TO" ; then
echo "git-bashrc configuration file is already sourced from ~/$INSTALL_TO)"
return
fi
cat <<- __EOF__ >> "$HOME/$INSTALL_TO"
# Source the git-bashrc configuration file.
# See: https://github.com/g1a/git-bashrc
source "$SCRIPT_DIR/git-bashrc"
__EOF__
echo "Installed 'source git-bashrc' in ~/$INSTALL_TO"
# Source fd so that it is available in this shell.
source $SCRIPT_DIR/git-bashrc