-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_profile
202 lines (180 loc) · 6.43 KB
/
.bash_profile
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Add go library to path
if [[ -d ${HOME}/go ]]; then
export GOPATH=${HOME}/go
export PATH=${PATH}:${GOPATH}/bin
fi
# Set prompt during privilege escalation
export SUDO_PS1='\h:\W \u\$ '
# Adds a countdown feature to the read timeout
read_prompt() {
trap true INT TERM EXIT
if [[ $# -lt 2 ]]; then
exit 0
fi
COUNTDOWN=${1}
MESSAGE=${2}
while [[ $COUNTDOWN -ge 0 ]]
do
tput hpa $((${#MESSAGE} + 11))
tput sc
tput cub 80
tput el
echo -n $MESSAGE [y/n] [${COUNTDOWN}] >&2
((COUNTDOWN--))
tput rc
sleep 1
done &
read -t $1 -n 1 -r; kill -9 $!; wait $! 2>/dev/null
}
# Spinner for long running processes with return value check
spinner() {
trap true INT TERM EXIT
case $1 in
start)
SPINNER_CHARS='\|/-'
SPINNER_MESSAGE=${2}
tput cud1
while true
do
tput hpa $((${#SPINNER_MESSAGE} + 2))
tput sc
tput cub 80
tput el
echo -n $SPINNER_MESSAGE ${SPINNER_CHARS:i++%${#SPINNER_CHARS}:1}
tput rc
sleep 0.1
done
;;
stop)
SPINNER_RV=${2}
SPINNER_PID=${3}
kill -9 $SPINNER_PID; wait $! 2>/dev/null
echo -n $(tput kbs)
echo -n [
if [[ $SPINNER_RV -eq 0 ]]; then
echo -n $(tput setaf 2)OK$(tput sgr0)
else
echo -n $(tput setaf 1)FAIL$(tput sgr0)
fi
echo ]
;;
esac
}
# Source ~/.profile
# Set user configurable environment variables here
if [[ -s ~/.profile ]]; then
source ~/.profile
fi
# Source ~/.bashrc
# Evaluated commands are executed through ~/.eval
if [[ -s ~/.bashrc ]]; then
. ~/.bashrc
fi
# Source ~/.alias
# Set command aliases here
if [[ -f ~/.alias ]]; then
. ~/.alias
fi
# Run ssh-agent, set the appropriate environment and kill the agent PID on exit
if [[ $- =~ i ]] && [[ -x $(which ssh-add 2>/dev/null) ]]; then
eval $(ssh-agent -s) > /dev/null 2>&1
trap "ssh-agent -k" EXIT
# Add SSH keys to the OS agent and add the ability to override the identity lifetime by
# setting the environment variable SSH_IDENTITY_LIFETIME=N in ~/.profile
if [[ $(uname -s) == Linux ]] && [[ -S $SSH_AUTH_SOCK ]]; then
ssh-add -t ${SSH_IDENTITY_LIFETIME:-604800}
elif [[ $(uname -s) == Darwin ]] && [[ -S $SSH_AUTH_SOCK ]]; then
ssh-add -K 2>/dev/null
ssh-add -A 2>/dev/null
fi
fi
# Global git settings
# Override by setting the environment variables GIT_NAME and GIT_EMAIL in ~/.profile
if [[ -x $(which git 2>/dev/null) ]]; then
git config --global alias.last 'log -1 HEAD'
git config --global alias.tree 'log --graph --decorate --pretty=oneline --abbrev-commit'
git config --global alias.unstage 'reset HEAD --'
git config --global user.email "${GIT_EMAIL:-anonymous@localhost}"
git config --global user.name "${GIT_NAME:-Anonymous}"
else
echo -e "$(tput setaf 3)Warning:$(tput sgr0) git not found in your path\nFunctionality that uses git will be disabled"
fi
# Git Prompt settings
# Set config variables first
# GIT_PROMPT_ONLY_IN_REPO=1
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# Needed for new prompt theme management
__GIT_PROMPT_DIR=~/.bash-git-prompt
GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
GIT_PROMPT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files
# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10
if [[ -x $(which git 2>/dev/null) ]] && [[ $(uname -s) != Darwin ]] && [[ $(git --version | awk '{print $NF,"\n1.7.10"}' | sort -Vr | head -n1) == 1.7.10 ]]; then
GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh
fi
# GIT_PROMPT_START=... # uncomment for custom prompt start sequence
# GIT_PROMPT_END=... # uncomment for custom prompt end sequence
GIT_PROMPT_LEADING_SPACE=0
GIT_PROMPT_START="[\u@\h \W]"
if [[ $UID == 0 ]]; then
GIT_PROMPT_END='# '
else
GIT_PROMPT_END='$ '
fi
# as last entry source the gitprompt script
# GIT_PROMPT_THEME=Custom # use custom .git-prompt-colors.sh
# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme
GIT_PROMPT_THEME=Chmike
# Source ~/.bash-git-prompt/gitprompt.sh
if [[ -x $(which git 2>/dev/null) ]] && [[ -f ~/.bash-git-prompt/gitprompt.sh ]]; then
. ~/.bash-git-prompt/gitprompt.sh
fi
# Keep dotfiles up to date automatically by running ~/.update_dotfiles.sh
# Also provide the ability to disable by setting the environment variable UPDATE_DOTFILES=false in ~/.profile
# Override read timeout by setting the environment variable UPDATE_DOTFILES_TIMEOUT=N in ~/.profile
if [[ -x $(which git 2>/dev/null) ]]; then
if [[ -x ~/.update_dotfiles.sh ]] && $(${UPDATE_DOTFILES:-true}); then
read_prompt ${UPDATE_DOTFILES_TIMEOUT:-5} "Update dotfiles? (s to skip)"
case $REPLY in
Y | y ) EXECUTE_UPDATE=true; unset REPLY;;
S | s ) SKIP=true; unset REPLY;;
* ) echo -e "\nContinuing..."; unset REPLY;;
esac
if $(${EXECUTE_UPDATE:-false}); then
spinner start "Updating dotfiles" & ~/.update_dotfiles.sh > /dev/null 2>&1
spinner stop $? $!
else
echo -e "\nSkipping dotfiles update\nRun '~/.update_dotfiles.sh' to update dotfiles manually"
fi
else
echo "Update dotfiles is disabled, unset UPDATE_DOTFILES to enable"
fi
fi
# Source only on Linux specific operating systems
if [[ $(uname -s) == Linux ]]; then
. ~/.linux.sh
fi
# Source only on Darwin specific operating systems
if [[ $(uname -s) == Darwin ]]; then
. ~/.darwin.sh
fi
# Cleanup
unset EXECUTE_UPDATE SKIP
# Install RVM option
# Provide the ability to install RVM automatically by setting the environment variable INSTALL_RVM=true in ~/.profile
# Override read timeout by setting the environment variable INSTALL_RVM_TIMEOUT=N in ~/.profile
if [[ ! -f ${HOME}/.rvm/scripts/rvm ]] && [[ -x $(which curl 2>/dev/null) ]] && ${INSTALL_RVM:-false} > /dev/null 2>&1; then
read_prompt ${INSTALL_RVM_TIMEOUT:-5} "Install RVM?"
if [[ $REPLY =~ ^[Yy]$ ]]; then
unset REPLY
echo "Installing RVM"
# Test for GPG key
if ! gpg --list-keys [email protected] >/dev/null 2>&1; then
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
fi
command curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enable
else
echo -e "\nSkipping RVM install\nInstall RVM manually or set the environment variable INSTALL_RVM=true in ~/.profile"
fi
fi
# Default RVM function
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*