Skip to content

Instantly share code, notes, and snippets.

@inebritov
Created January 15, 2016 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inebritov/e9e9b4149115f642d8cd to your computer and use it in GitHub Desktop.
Save inebritov/e9e9b4149115f642d8cd to your computer and use it in GitHub Desktop.
.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
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
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
[ "$TERM" = "xterm" ] && TERM="xterm-256color"
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# Software Flow Control
stty -ixon
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's 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=yes
TERM=xterm-256color
else
color_prompt=
fi
fi
## Print nickname for git/hg/bzr/svn version control in CWD
## Optional $1 of format string for printf, default "(%s) "
function find_vcs_branch {
local dir="$PWD"
local vcs
local nick
while [[ "$dir" != "/" ]]; do
for vcs in git hg svn bzr; do
if [[ -d "$dir/.$vcs" ]] && hash "$vcs" &>/dev/null; then
case "$vcs" in
git) __git_ps1 "${1:-(%s) }"; return;;
hg) nick=$(hg branch 2>/dev/null);;
svn) nick=$(svn info 2>/dev/null\
| grep -e '^Repository Root:'\
| sed -e 's#.*/##');;
bzr)
local conf="${dir}/.bzr/branch/branch.conf" # normal branch
[[ -f "$conf" ]] && nick=$(grep -E '^nickname =' "$conf" | cut -d' ' -f 3)
conf="${dir}/.bzr/branch/location" # colo/lightweight branch
[[ -z "$nick" ]] && [[ -f "$conf" ]] && nick="$(basename "$(< $conf)")"
[[ -z "$nick" ]] && nick="$(basename "$(readlink -f "$dir")")";;
esac
[[ -n "$nick" ]] && printf "${1:-(%s) }" "$nick"
return 0
fi
done
dir="$(dirname "$dir")"
done
}
# colors
color_white=$'\e[00;37m'
color_cyan=$'\e[00;36m'
color_green=$'\e[1;32m'
color_yellow=$'\e[1;33m'
color_magenta=$'\e[1;35m'
color_normal=$'\e[0m'
# begining of prompt
user_prompt='${debian_chroot:+($debian_chroot)}\[$color_cyan\]\w'
# vcs branch
if [ find_vcs_branch ]; then
user_prompt="$user_prompt \[$color_green\]\$(find_vcs_branch "$2")"
fi
# sign at the end of prompt
if [ `whoami` = "root" ]; then
user_prompt="$user_prompt\[$color_yellow\]#"
else
user_prompt="$user_prompt\[$color_magenta\]\\$"
fi
if [ "$color_prompt" = yes ]; then
PS1="$user_prompt\[$color_normal\] "
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# some more ls aliases
alias ls='ls --color'
alias ll='ls -alhF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# 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).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export EDITOR=vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment