Skip to content

Instantly share code, notes, and snippets.

@typhonius
Created February 23, 2013 03:02
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 typhonius/5018157 to your computer and use it in GitHub Desktop.
Save typhonius/5018157 to your computer and use it in GitHub Desktop.
My bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
fi
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[\u@\h:\l \W]\\$ "
# fi
# to your custom modification shell script in /etc/profile.d/ directory
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# By default, we want umask to get set. This sets it for non-login shell.
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
fi
# vim:ts=4:sw=4
# Custom adam shit
# 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
# ... or force ignoredups and ignorespace
#HISTCONTROL=ignoredups:ignorespace
# 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
# set a fancy prompt (non-color, unless we know we "want" color)
#case "$TERM" in
# xterm-color) color_prompt=yes;;
#esac
# 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
# else
# color_prompt=
# fi
#fi
#if [ "$color_prompt" = yes ]; then
# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\$(check_readonly)[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#else
# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
#fi
#unset color_prompt force_color_prompt
# 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
# enable color support of ls and also add handy aliases
#if [ -x /usr/bin/dircolors ]; then
# test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
# alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
# alias grep='grep --color=auto'
# alias fgrep='fgrep --color=auto'
# alias egrep='egrep --color=auto'
#fi
# some more ls aliases
#alias ll='ls -alF'
#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$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#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).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
# even more custom
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#compress() # create .tar.gz archive
#{
# tar -cvzf $1 $2
#}
#netinfo - shows network information for your system
#netinfo ()
#{
#echo "--------------- Network Information ---------------"
#/sbin/ifconfig | awk /'inet addr/ {print $2}'
#/sbin/ifconfig | awk /'Bcast/ {print $3}'
#/sbin/ifconfig | awk /'inet addr/ {print $4}'
#/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
#myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
#echo "${myip}"
#echo "---------------------------------------------------"
#}
#dirsize - finds directory sizes and lists them for the current directory
#dirsize ()
#{
#du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
#egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
#egrep '^ *[0-9.]*M' /tmp/list
#egrep '^ *[0-9.]*G' /tmp/list
#rm -rf /tmp/list
#}
#psgrep() {
# if [ ! -z $1 ] ; then
# echo "Grepping for processes matching $1..."
# ps aux | grep $1 | grep -v grep
# else
# echo "!! Need name to grep for"
# fi
#}
#cpg (){
# if [ -d "$2" ];then
# cp $1 $2 && cd $2
#else
# cp $1 $2
#fi
#}
#mvg (){
# if [ -d "$2" ];then
# mv $1 $2 && cd $2
# else
# mv $1 $2
# fi
#}
# Directory navigation aliases
#alias ..='cd ..'
#alias ...='cd ../..'
#alias ....='cd ../../..'
#alias .....='cd ../../../..'
#alias cim='vim'
#alias back='cd $OLDPWD'
#alias root='sudo su'
#alias runlevel='sudo /sbin/init'
#alias grep='grep --color=auto'
#alias dfh='df -h'
#alias gvim='gvim -geom 84x26'
#alias start='dbus-launch startx'
#alias ls='ls -h --color=auto'
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
#alias svim='sudo vim'
#alias h='cd'
#alias rm='rm -iv'
# Prompt
BGREEN='\[\033[1;32m\]'
GREEN='\[\033[1;32m\]'
BRED='\[\033[1;31m\]'
RED='\[\033[1;31m\]'
BBLUE='\[\033[1;34m\]'
BLUE='\[\033[0;34m\]'
NORMAL='\[\033[00m\]'
PURPLE='\[\033[1;35m\]'
#PS1="${PURPLE}[\d \t] ${RED}\u${BLUE}@${GREEN}\h${BRED}${BLUE} (${RED}\w${BLUE})${RED}\${BLUE}\!${RED} \$ ${NORMAL} "
#PS1="${PURPLE}[\d \t] ${RED}\u${BLUE}@${GREEN}\h${BRED}${BLUE} (${RED}\w${BLUE})${RED}\$(check_readonly)${NORMAL}\$(parse_git_branch)${BGREEN}\$(parse_svn_branch) ${BLUE}\!${RED} \$ ${NORMAL} "
PS1="${PURPLE}[\d \t] ${RED}\u${BLUE}@${GREEN}\h${BRED}${BLUE} (${RED}\w${BLUE})${RED}\$(check_readonly)${NORMAL}\$(parse_git_branch) ${BLUE}\!${RED} \$ ${NORMAL} "
#export EDITOR=vim
#alias sudo='sudo '
#alias dwim='vim -u ~/.drupalvimrc'
function check_readonly() {
[[ ! -w . ]] && echo -e " [ro] "
}
# These functions adapted from:
# http://hocuspokus.net/2009/07/add-git-and-svn-branch-to-bash-prompt/
function parse_git_branch () {
#git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#'
git rev-parse --symbolic-full-name --abbrev-ref HEAD 2> /dev/null | sed 's#\(.*\)# (git::\1)#'
}
#function parse_svn_branch() {
# parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk '{print " (svn::"$1")" }'
#}
#function parse_svn_url() {
# svn info 2>/dev/null | sed -ne 's#^URL: ##p'
#}
#function parse_svn_repository_root() {
# svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p'
#}
#export PATH="$PATH:/sbin:/usr/sbin:usr/local/sbin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment