forked from hkjn/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bash_profile
More file actions
205 lines (173 loc) · 6.28 KB
/
.bash_profile
File metadata and controls
205 lines (173 loc) · 6.28 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
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
203
204
205
# ~/.bashrc: executed by bash(1) for non-login shells.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoreboth
# Append to the history file, don't overwrite it.
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
color_prompt=yes
if ! [ -x /usr/bin/tput ] || ! tput setaf 1 >&/dev/null; then
# We have no color support; not compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=
fi
# echo the current git branch
gitbranch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# echo user and host
userhost() {
local lgreen='\[\033[01;32m\]'
local normal='\[\033[00m\]'
local dgray='\[\033[1;30m\]'
echo "${lgreen}\u@\h${dgray}♾${normal}"
}
# echo current working directory
workdir() {
local lblue='\[\033[01;34m\]'
local normal='\[\033[00m\]'
echo "${lblue}\w${normal}"
}
# echo extra info, if available
#
# TODO(hkjn): Improve the setup for "extrainfo" and make it extensible:
# 1. Read from some inmemory store / unix socket or similar, so no
# filesystem access is necessary just to draw the prompt
# 2. Have separate timer-based job that checks stuff and writes to socket:
# - connectivity (can ping 8.8.8.8, DNS resolution works, VPN is up/down)
# - number of running docker containers (specifically, hkjn/fileserver containers)
extrainfo() {
local lcyan='\[\033[1;36m\]'
local normal='\[\033[00m\]'
local red='\[\e[0;31m\]'
local awscreds=''
local dgray='\[\033[1;30m\]'
if [[ ! -e '.aws/creds.env' ]]; then
return
fi
local expiry=$(grep -Eo '[0-9]{10}$' .aws/creds.env)
local secsleft=$(($expiry-$(date +%s)))
if [[ $secsleft -lt 3600 ]]; then
# Expired credentials. (Apparently.)
awscreds="💩"
elif [[ $secsleft -lt 4000 ]]; then
# Credentails about to expire.
awscreds="💣"
else
# Good credentials.
awscreds="${lcyan}✓"
fi
local stage=${STAGE:-""}
local stageinfo="?"
if [[ "$stage" == *"prod"* ]]; then
stageinfo="${lcyan}☠"
elif [[ "$stage" == *"stag"* ]]; then
stageinfo="${lcyan}⚠"
else
stageinfo="${lcyan}☯"
fi
echo "${dgray}♾${awscreds}${dgray}♾${stageinfo}${normal}"
}
PROMPT_COMMAND=__prompt_command
# Set prompt according to exit status and other info.
__prompt_command() {
local EXIT="$?"
local prompt="►"
local dgray='\[\033[1;30m\]'
local green='\[\033[00;32m\]'
local lwhite='\[\033[01;11m\]'
local normal='\[\033[00m\]'
local red='\[\e[0;31m\]'
# TODO: red/green here doesn't seem to exist consistently (alpine),
# even though other colors do. Switch?
local pcolor="$green"
if [ $EXIT != 0 ]; then
pcolor="$red"
fi
# 木 人 ♪
if [ "$color_prompt" = yes ]; then
PS1="${lwhite}\$(gitbranch)${dgray}♾${normal}$(userhost)$(workdir)$(extrainfo) \n${pcolor}${prompt}$normal "
else
PS1="$"
fi
}
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# Pull in useful functions.
BASH_FUNCS="$HOME/src/hkjn.me/scripts/bash_funcs.sh"
if [ -e "$BASH_FUNCS" ]; then
source "$BASH_FUNCS"
else
echo "No '$BASH_FUNCS' found. Try 'go get hkjn.me/scripts'?"
fi
KLARNA_BASH="$HOME/src/stash.int.klarna.net/henrik.jonsson/hacks/klarna_bash.sh"
if [ -e "$KLARNA_BASH" ]; then
source "$KLARNA_BASH"
fi
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
[ -f /etc/bash_completion ] && source /etc/bash_completion
alias pp="git pull && git push"
alias gdc="git diff --cached"
alias gs="git status"
alias docker_rmcontainers='docker rm $(docker ps -a -q -f status=exited)'
alias docker_rmall='docker rm -f $(docker ps -a -q) && docker rmi $(docker images -q --filter "dangling=true")'
alias docker_rmimages='docker rmi $(docker images -q --filter "dangling=true")'
alias e="emacsclient -nw $1"
alias ec="e $HOME/.bash_profile"
alias ecf="e $HOME/.ssh/config"
alias rf="[ -e $HOME/.bash_profile ] && source $HOME/.bash_profile || source $HOME/.bashrc"
alias tc="tmux new -s $1"
alias ta="tmux attach -d -t $1"
alias ll='ls -hsAl'
alias mp="mplayer -af scaletempo $@"
alias mp50="mplayer -af scaletempo -fs -panscanrange -5 $@"
alias xclip="xclip -selection c"
alias shlogs="less ${HOME}/.shell_logs/${HOSTNAME}"
export LANG="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export EDITOR=nano
export GOPATH=${HOME}
export PATH=/usr/local/go/bin:/usr/local/homebrew/opt/gnu-tar/libexec/gnubin:/usr/local/homebrew/opt/curl/bin:/usr/local/homebrew/bin:/usr/local/homebrew/sbin:/usr/local/homebrew/Cellar/coreutils/8.25/libexec/gnubin/:${GOPATH}/src/hkjn.me/scripts:${GOPATH}/src/hkjn.me/scripts/tools:${HOME}/bin:.:$PATH
export PYTHONPATH=.:..
# Don't scatter __pycache__ directories all over the place.
export PYTHONDONTWRITEBYTECODE=1
# GPG always wants to know what TTY it's running on.
export GPG_TTY=$(tty)
export CLOUDSDK_PYTHON=python2
if [ -d ~/google-cloud-sdk ]; then
# The next line updates PATH for the Google Cloud SDK.
source "$HOME/google-cloud-sdk/path.bash.inc"
# The next line enables bash completion for gcloud.
source "$HOME/google-cloud-sdk/completion.bash.inc"
fi
# Allow current user to connect to X11 socket from any host; required
# to run graphical Docker containers. But not on OS X, since even
# though xhost exists, on at least OS X Mavericks it just stalls
# indefinitely if invoked, preventing new bash sessions.
if which xhost > /dev/null 2>&1 && [ ! -z $DISPLAY ] && [ $(uname) != "Darwin" ]; then
xhost +si:localuser:$USER >/dev/null
xhost +si:localuser:root >/dev/null
fi