1 | IS_OSX=0 |
---|
2 | uname -a | fgrep -q Darwin && IS_OSX=1 |
---|
3 | export IS_OSX="$IS_OSX" |
---|
4 | |
---|
5 | # Build up PATH |
---|
6 | tmp_path= |
---|
7 | for dir in "$HOME/node_modules/.bin" \ |
---|
8 | "$HOME/.keybase/bin" \ |
---|
9 | "$gem_bindir" \ |
---|
10 | "$HOME/usr/bin" \ |
---|
11 | "$HOME/dev/misc-scripts"; do |
---|
12 | [ -z "$dir" ] && continue |
---|
13 | if [ -d "$dir" ]; then |
---|
14 | if [ -z "$tmp_path" ]; then |
---|
15 | tmp_path="$dir" |
---|
16 | else |
---|
17 | tmp_path="${tmp_path}:${dir}" |
---|
18 | fi |
---|
19 | fi |
---|
20 | done |
---|
21 | |
---|
22 | export PATH="${tmp_path}:$PATH" |
---|
23 | |
---|
24 | # Local Ruby installations only |
---|
25 | _GEM_VERSION=2.0.0 |
---|
26 | export GEM_HOME="$HOME/.gem/ruby/$_GEM_VERSION" |
---|
27 | export PATH="$GEM_HOME/bin:$PATH" |
---|
28 | |
---|
29 | if [ -d '/opt/local/bin' ]; then |
---|
30 | export PATH="/opt/local/libexec/gnubin:/opt/local/bin:$PATH" |
---|
31 | fi |
---|
32 | |
---|
33 | # Variables that are still useful in non-interactive |
---|
34 | export PYTHONSTARTUP=~/.pythonrc |
---|
35 | export EIX_LIMIT=0 |
---|
36 | |
---|
37 | # If not running interactively, don't do anything |
---|
38 | [ -z "$PS1" ] && return |
---|
39 | |
---|
40 | # Disable caps lock key |
---|
41 | if [ ! -z "$DISPLAY" ] && ! echo "$DISPLAY" | fgrep -q xquartz; then |
---|
42 | setxkbmap -option ctrl:nocaps |
---|
43 | xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' |
---|
44 | # Still force numlock |
---|
45 | if which numlockx &>/dev/null; then |
---|
46 | numlockx off |
---|
47 | numlockx on |
---|
48 | fi |
---|
49 | fi |
---|
50 | |
---|
51 | # Global hostname |
---|
52 | export HOSTNAME=$(hostname) |
---|
53 | |
---|
54 | # SSH/GPG agent via keychain |
---|
55 | if which keychain &>/dev/null; then |
---|
56 | [ -f "$HOME/.keychain/${HOSTNAME}-sh" ] && . "$HOME/.keychain/${HOSTNAME}-sh" && \ |
---|
57 | keychain -q --host "$HOSTNAME" "$HOME/.ssh/id_rsa" |
---|
58 | [ -f "$HOME/.keychain/${HOSTNAME}-sh-gpg" ] && . "$HOME/.keychain/${HOSTNAME}-sh-gpg" |
---|
59 | fi |
---|
60 | |
---|
61 | # vi mode! |
---|
62 | # http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.pdf |
---|
63 | set -o vi |
---|
64 | |
---|
65 | # don't put duplicate lines in the history. |
---|
66 | export HISTCONTROL=ignoredups:erasedups |
---|
67 | # ... and ignore same sucessive entries. |
---|
68 | export HISTCONTROL=ignoreboth |
---|
69 | # bigger history |
---|
70 | export HISTSIZE=10000 |
---|
71 | export HISTFILESIZE=100000 |
---|
72 | # Global hostname |
---|
73 | export HOSTNAME=$(hostname) |
---|
74 | |
---|
75 | # check the window size after each command and, if necessary, |
---|
76 | # update the values of LINES and COLUMNS. |
---|
77 | shopt -s checkwinsize |
---|
78 | |
---|
79 | # Enable other cool events |
---|
80 | shopt -s extglob |
---|
81 | |
---|
82 | # Append history entries; do not overwrite them |
---|
83 | shopt -s histappend |
---|
84 | |
---|
85 | # If this is an xterm set the title to user@host:dir |
---|
86 | case "$TERM" in |
---|
87 | rxvt|*term) |
---|
88 | PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' |
---|
89 | ;; |
---|
90 | *) |
---|
91 | ;; |
---|
92 | esac |
---|
93 | |
---|
94 | # User agent for Lynx and links |
---|
95 | export USER_AGENT='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36' |
---|
96 | |
---|
97 | # Aliases |
---|
98 | [ -f ~/.bash_aliases ] && . ~/.bash_aliases |
---|
99 | |
---|
100 | # Functions |
---|
101 | [ -f ~/.bash_functions ] && . ~/.bash_functions |
---|
102 | |
---|
103 | # Bash completion |
---|
104 | if [[ "$(uname -s)" = 'Linux' ]]; then |
---|
105 | # Gentoo: Git Bash completion bug? |
---|
106 | for i in git git-flow hubflow; do |
---|
107 | [ -f "/usr/share/bash-completion/completions/$i" ] && . "/usr/share/bash-completion/completions/$i" |
---|
108 | done |
---|
109 | elif [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then |
---|
110 | # MacPorts |
---|
111 | . /opt/local/etc/profile.d/bash_completion.sh |
---|
112 | fi |
---|
113 | |
---|
114 | # Extra files, loaded in alpahbetical order |
---|
115 | if [ -d "$HOME/.bash.d" ] && (($(find "$HOME/.bash.d/" -maxdepth 1 -type f | wc -l) > 0)); then |
---|
116 | for i in "$HOME/.bash.d/"*; do |
---|
117 | . "$i" |
---|
118 | done |
---|
119 | fi |
---|
120 | |
---|
121 | ## Variables |
---|
122 | if [ "$UID" -gt 0 ]; then |
---|
123 | export PS1='\[\033[1;36m\]\u@\h\[\033[01;37m\] \w $ \[\033[00m\]' |
---|
124 | fi |
---|
125 | |
---|
126 | # ibus |
---|
127 | if which ibus-daemon &>/dev/null; then |
---|
128 | export GTK_IM_MODULE=ibus |
---|
129 | export QT_IM_MODULE=ibus |
---|
130 | export XMODIFIERS="@im=ibus" |
---|
131 | fi |
---|
132 | |
---|
133 | # Disable git merge prompt |
---|
134 | export GIT_MERGE_AUTOEDIT=no |
---|
135 | |
---|
136 | # Editor in general (used by git and others) |
---|
137 | export EDITOR=vim |
---|
138 | |
---|
139 | if (("$UID" != 0)) && (($IS_OSX == 0)); then |
---|
140 | umask 0027 |
---|
141 | fi |
---|
142 | |
---|
143 | if (($IS_OSX == 1)); then |
---|
144 | umask 0022 |
---|
145 | fi |
---|
146 | |
---|
147 | # virtualenvwrapper |
---|
148 | sourced_wrapper=0 |
---|
149 | if which virtualenvwrapper.sh &>/dev/null; then |
---|
150 | source $(which virtualenvwrapper.sh) |
---|
151 | sourced_wrapper=1 |
---|
152 | fi |
---|
153 | if (($sourced_wrapper == 0)) && which virtualenvwrapper.sh-2.7 &>/dev/null; then |
---|
154 | source $(which virtualenvwrapper.sh-2.7) |
---|
155 | fi |
---|
156 | |
---|
157 | # Plain OS X way to get colours for non-GNU ls |
---|
158 | if (($IS_OSX == 1)) && ! ls --help 2>&1 | fgrep -q GNU; then |
---|
159 | export CLICOLOR=1 |
---|
160 | export LSCOLORS=ExFxCxDxBxegedabagacad |
---|
161 | fi |
---|
162 | |
---|
163 | # tmux |
---|
164 | if which tmux &>/dev/null && ! echo "$TERM" | grep -q screen && [ -z "$TMUX" ] && [ "$UID" -ne 0 ]; then |
---|
165 | # if not inside a tmux session, and if no session is started, start a new session |
---|
166 | # TODO This similar branching is ugly |
---|
167 | if tmux ls 2>&1 | egrep -q '^failed'; then |
---|
168 | tmux new-session |
---|
169 | elif ! tmux ls 2>&1 | egrep -q '\(attached\)$'; then # no attached instances |
---|
170 | tmux attach # attach to the preferred one |
---|
171 | else |
---|
172 | # Get first non-attached and attach to it |
---|
173 | not_attached=$(tmux ls -F '#S #{?session_attached,attached,not attached}' 2>&1 |\ |
---|
174 | grep 'not attached' |\ |
---|
175 | awk '{ print $1 }' |\ |
---|
176 | head -n 1) |
---|
177 | if [ -z "$not_attached" ]; then |
---|
178 | tmux new-session |
---|
179 | else |
---|
180 | tmux attach -d -t "$not_attached" |
---|
181 | fi |
---|
182 | fi |
---|
183 | fi |
---|
184 | |
---|
185 | # vim: set filetype=bash: |
---|
186 | # kate: syntax Bash; replace-tabs: true; replace-tabs-save: true |
---|