1 # ~/.bashrc: executed by bash(1) for non-login shells.
2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
5 # If not running interactively, don't do anything
11 # don't put duplicate lines or lines starting with space in the history.
12 # See bash(1) for more options
13 HISTCONTROL=ignoreboth
15 # append to the history file, don't overwrite it
18 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
22 # check the window size after each command and, if necessary,
23 # update the values of LINES and COLUMNS.
26 # make less more friendly for non-text input files, see lesspipe(1)
27 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
29 # set variable identifying the chroot you work in (used in the prompt below)
30 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
31 debian_chroot=$(cat /etc/debian_chroot)
35 # colored GCC warnings and errors
36 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
39 if [ -f ~/.bash_aliases ]; then
43 eval `dircolors ~/.dir_colors`
45 # enable programmable completion features (you don't need to enable
46 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
47 # sources /etc/bash.bashrc).
48 if ! shopt -oq posix; then
49 if [ -f /usr/share/bash-completion/bash_completion ]; then
50 . /usr/share/bash-completion/bash_completion
51 elif [ -f /etc/bash_completion ]; then
52 . /etc/bash_completion
57 # Some simple note taking functions
59 $EDITOR ~/notes/"$*".md
63 ls -cR ~/notes/ | grep "$*"
67 Green=$(tput setaf 64)
69 Yellow=$(tput setaf 136)
70 Purple=$(tput setaf 61)
71 BGreen=$Green$(tput bold)
73 BYellow=$Yellow$(tput bold)
74 BPurple=$Purple$(tput bold)
76 Color_Off=$(tput sgr0)
78 # set up command prompt
79 function __prompt_command()
81 # capture the exit status of the last command
85 if [ $EXIT -eq 0 ]; then PS1+="\[$Green\][\!]\[$Color_Off\] "; else PS1+="\[$Red\][\!]\[$Color_Off\] "; fi
87 # if logged in via ssh shows the ip of the client
88 if [ -n "$SSH_CLIENT" ]; then
90 PS1+="\[$Yellow\]("$IP")\[$Color_Off\]";
93 # debian chroot stuff (take it or leave it)
94 PS1+="${debian_chroot:+($debian_chroot)}"
96 # basic information (user@host:path)
97 PS1+="\[$BRed\]\u\[$Color_Off\]@\[$BRed\]\h\[$Color_Off\]:\[$BPurple\]\w\[$Color_Off\] "
99 # check if inside git repo
100 local git_status="`git status -unormal 2>&1`"
101 if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
102 # parse the porcelain output of git status
103 if [[ "$git_status" =~ nothing\ to\ commit ]]; then
104 local Color_On=$Green
105 elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
106 local Color_On=$Purple
111 if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
112 branch=${BASH_REMATCH[1]}
114 # Detached HEAD. (branch=HEAD is a faster alternative.)
115 branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD`)"
118 # add the result to prompt
119 PS1+="\[$Color_On\][$branch]\[$Color_Off\] "
122 # prompt $ or # for root
125 PROMPT_COMMAND=__prompt_command