Ticket #46019: bashrc

File bashrc, 5.0 KB (added by Tatsh (Andrew Udvare), 10 years ago)
Line 
1IS_OSX=0
2uname -a | fgrep -q Darwin && IS_OSX=1
3export IS_OSX="$IS_OSX"
4
5# Build up PATH
6tmp_path=
7for 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
20done
21
22export PATH="${tmp_path}:$PATH"
23
24# Local Ruby installations only
25_GEM_VERSION=2.0.0
26export GEM_HOME="$HOME/.gem/ruby/$_GEM_VERSION"
27export PATH="$GEM_HOME/bin:$PATH"
28
29if [ -d '/opt/local/bin' ]; then
30    export PATH="/opt/local/libexec/gnubin:/opt/local/bin:$PATH"
31fi
32
33# Variables that are still useful in non-interactive
34export PYTHONSTARTUP=~/.pythonrc
35export EIX_LIMIT=0
36
37# If not running interactively, don't do anything
38[ -z "$PS1" ] && return
39
40# Disable caps lock key
41if [ ! -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
49fi
50
51# Global hostname
52export HOSTNAME=$(hostname)
53
54# SSH/GPG agent via keychain
55if 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"
59fi
60
61# vi mode!
62# http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.pdf
63set -o vi
64
65# don't put duplicate lines in the history.
66export HISTCONTROL=ignoredups:erasedups
67# ... and ignore same sucessive entries.
68export HISTCONTROL=ignoreboth
69# bigger history
70export HISTSIZE=10000
71export HISTFILESIZE=100000
72# Global hostname
73export HOSTNAME=$(hostname)
74
75# check the window size after each command and, if necessary,
76# update the values of LINES and COLUMNS.
77shopt -s checkwinsize
78
79# Enable other cool events
80shopt -s extglob
81
82# Append history entries; do not overwrite them
83shopt -s histappend
84
85# If this is an xterm set the title to user@host:dir
86case "$TERM" in
87rxvt|*term)
88        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
89    ;;
90*)
91    ;;
92esac
93
94# User agent for Lynx and links
95export 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
104if [[ "$(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
109elif [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
110    # MacPorts
111    . /opt/local/etc/profile.d/bash_completion.sh
112fi
113
114# Extra files, loaded in alpahbetical order
115if [ -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
119fi
120
121## Variables
122if [ "$UID" -gt 0 ]; then
123    export PS1='\[\033[1;36m\]\u@\h\[\033[01;37m\] \w $ \[\033[00m\]'
124fi
125
126# ibus
127if which ibus-daemon &>/dev/null; then
128    export GTK_IM_MODULE=ibus
129    export QT_IM_MODULE=ibus
130    export XMODIFIERS="@im=ibus"
131fi
132
133# Disable git merge prompt
134export GIT_MERGE_AUTOEDIT=no
135
136# Editor in general (used by git and others)
137export EDITOR=vim
138
139if (("$UID" != 0)) && (($IS_OSX == 0)); then
140    umask 0027
141fi
142
143if (($IS_OSX == 1)); then
144    umask 0022
145fi
146
147# virtualenvwrapper
148sourced_wrapper=0
149if which virtualenvwrapper.sh &>/dev/null; then
150    source $(which virtualenvwrapper.sh)
151    sourced_wrapper=1
152fi
153if (($sourced_wrapper == 0)) && which virtualenvwrapper.sh-2.7 &>/dev/null; then
154    source $(which virtualenvwrapper.sh-2.7)
155fi
156
157# Plain OS X way to get colours for non-GNU ls
158if (($IS_OSX == 1)) && ! ls --help 2>&1 | fgrep -q GNU; then
159    export CLICOLOR=1
160    export LSCOLORS=ExFxCxDxBxegedabagacad
161fi
162
163# tmux
164if 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
183fi
184
185# vim: set filetype=bash:
186# kate: syntax Bash; replace-tabs: true; replace-tabs-save: true