-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc.common
181 lines (156 loc) · 4.85 KB
/
bashrc.common
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
# If this is NOT an interactive shell (such as script or scp)
if ! [[ $- = *i* ]]; then
# Don't bother. At all.
return 1;
fi
# Enable terminal colors
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export HISTSIZE="GOTCHA"
# Other useful commands
alias ll="ls -la"
alias s="source ~/.bashrc.common"
alias dotfiles-update="git -C ~/.dotfiles/ pull origin"
alias prompt-autoinstall=". ~/.dotfiles/autoinstall.sh"
export PATH=$PATH:$(go env GOPATH)/bin
# Script state variables
EMULATOR=
BASH_COMPLETION_PATH=
# Get terminal emulator info
_promptGetEmulator () {
if [[ "$OSTYPE" == "darwin"* ]]; then
EMULATOR="unknown"
else
# Get the terminal emulator name inside the shell script
# See: https://unix.stackexchange.com/a/264353
local sid=$(ps -o sid= -p "$$")
local sid_as_integer=$((sid)) # strips blanks if any
local session_leader_parent=$(ps -o ppid= -p "$sid_as_integer")
local session_leader_parent_as_integer=$((session_leader_parent))
EMULATOR=$(ps -o comm= -p "$session_leader_parent_as_integer")
fi
}
_promptSetupNeovim () {
if ! [ -x "$(command -v python3)" ]; then
echo "Python3 is NOT installed. You should install python3 (required for deoplete)"
echo "Run: prompt-autoinstall"
fi
if ! [ -x "$(command -v pip3)" ]; then
echo "Pip3 is NOT installed. You should install pip3 (required for deoplete)"
echo "Run: prompt-autoinstall"
fi
if [ -x "$(command -v nvim)" ]; then
# So long and thanks for all the fish
alias vim="nvim"
if [ "$EMULATOR" == "lxterminal" ]; then
# Fix broken characters in lxterminal + neovim
# See: https://github.com/neovim/neovim/issues/5990
export VTE_VERSION="100"
fi
else
echo "neovim not installed"
echo "Run: prompt-autoinstall"
fi
}
_promptSetupDocker () {
if [ -x "$(command -v docker)" ]; then
alias dcu="docker-compose up -d"
alias dcs="docker-compose stop"
fi
}
_promptSetupDarwin () {
# I decided it doesn't make sense to reinstall this SDK outside of Android studio
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
export JDK_HOME="$JAVA_HOME"
export JRE_HOME="$JAVA_HOME/jre"
export PATH="$JDK_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/platform-tools:$PATH"
if [ -x "$(command -v brew)" ]; then
BASH_COMPLETION_PATH=$(brew --prefix)/etc/bash_completion
else
echo "brew not installed"
echo "Run: prompt-autoinstall"
fi
}
_promptSetupBashCompletion () {
if [[ -f "$BASH_COMPLETION_PATH" ]]; then
. "$BASH_COMPLETION_PATH"
# Add GIT autocompletion in bash
source ~/.git-completion.bash
else
echo "bash-completion not installed"
echo "Run: prompt-autoinstall"
fi
}
_promptSetComputerTag () {
# Map my computer names to super cool emoji
case `hostname` in
MBLPPXNG8WL.local)
export COMPUTER_TAG="🌶 ";;
avocado)
export COMPUTER_TAG="🥑 ";;
raspberrypi)
export COMPUTER_TAG="🥧 ";;
Lees-MacBook-Pro.local)
export COMPUTER_TAG="🐝 ";;
*)
export COMPUTER_TAG="`hostname` ";;
esac
# Backup prompt in case I want to run `prompt_off` and disable liquid prompt
export PS1="${COMPUTER_TAG}"
}
_promptSetupLiquidprompt () {
local COMPUTER_TAG=$1
if [[ -d ~/liquidprompt/ ]]; then
# Liquid prompt: Hide the username unless I'm another user
export LP_USER_ALWAYS=0
# Liquid prompt: Special variables
LP_PS1_PREFIX="\n"
LP_PS1_POSTFIX="\n${COMPUTER_TAG}"
source ~/liquidprompt/liquidprompt
else
echo "liquidprompt not installed"
echo "Run: prompt-autoinstall"
fi
}
_promptFixLocale () {
# Fix strange errors that pop up when our locale is not set
# See: https://stackoverflow.com/a/8161863
export LANG="en_US.UTF-8"
export LC_ALL="$LANG"
}
_promptCheckDotfiles () {
# Check the date and time the last git fetch was executed
# See: https://stackoverflow.com/a/9229377
if [[ "$OSTYPE" == "darwin"* ]]; then
local last_fetch=`stat -f '%m' ~/.dotfiles/.git/FETCH_HEAD`
else
local last_fetch=`stat -c '%Y' ~/.dotfiles/.git/FETCH_HEAD`
fi
# Best method to Perform timestamp comparison in bash
# See: https://stackoverflow.com/a/205694
local ts=`date '+%s'`
local diff=$((ts - last_fetch))
local oneDay=(60 * 60 * 24)
if ! [ $diff -gt $oneDay ]; then
exit
fi
git -C ~/.dotfiles fetch
if [ $(git -C ~/.dotfiles rev-parse HEAD) != $(git -C ~/.dotfiles rev-parse @{u}) ]; then
echo "Hey there! Your dotfiles are out of date!"
echo "Run dotfiles-update to fix it."
echo "If you've made changes, you need to check those changes in!"
fi
}
_promptGetEmulator
_promptCheckDotfiles &
_promptSetupNeovim
_promptSetupDocker
_promptFixLocale
if [[ "$OSTYPE" == "darwin"* ]]; then
_promptSetupDarwin
else
BASH_COMPLETION_PATH=/usr/share/bash-completion/bash_completion
fi
_promptSetupBashCompletion
_promptSetComputerTag
_promptSetupLiquidprompt "$COMPUTER_TAG"