Last active
March 28, 2017 23:27
-
-
Save ofus/7eff17e2eaf0758db428 to your computer and use it in GitHub Desktop.
A simple bashrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ANSI color codes | |
RS="\[\033[0m\]" # reset | |
HC="\[\033[1m\]" # hicolor | |
UL="\[\033[4m\]" # underline | |
INV="\[\033[7m\]" # inverse background and foreground | |
FBLK="\[\033[30m\]" # foreground black | |
FRED="\[\033[31m\]" # foreground red | |
FGRN="\[\033[32m\]" # foreground green | |
FYEL="\[\033[33m\]" # foreground yellow | |
FBLE="\[\033[34m\]" # foreground blue | |
FMAG="\[\033[35m\]" # foreground magenta | |
FCYN="\[\033[36m\]" # foreground cyan | |
FWHT="\[\033[37m\]" # foreground white | |
BBLK="\[\033[40m\]" # background black | |
BRED="\[\033[41m\]" # background red | |
BGRN="\[\033[42m\]" # background green | |
BYEL="\[\033[43m\]" # background yellow | |
BBLE="\[\033[44m\]" # background blue | |
BMAG="\[\033[45m\]" # background magenta | |
BCYN="\[\033[46m\]" # background cyan | |
BWHT="\[\033[47m\]" # background white | |
BLACK='\e[0;30m' | |
BLUE='\e[0;34m' | |
GREEN='\e[0;32m' | |
CYAN='\e[0;36m' | |
RED='\e[0;31m' | |
PURPLE='\e[0;35m' | |
BROWN='\e[0;33m' | |
LIGHTGRAY='\e[0;37m' | |
DARKGRAY='\e[1;30m' | |
LIGHTBLUE='\e[1;34m' | |
LIGHTGREEN='\e[1;32m' | |
LIGHTCYAN='\e[1;36m' | |
LIGHTRED='\e[1;31m' | |
LIGHTPURPLE='\e[1;35m' | |
YELLOW='\e[1;33m' | |
WHITE='\e[1;37m' | |
ORANGE="\033[1;33m" | |
##### SETTINGS ################################################################# | |
# Source .bashrc for non-interactive Bash shells | |
export BASH_ENV=~/.bashrc | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(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 | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' | |
;; | |
*) | |
;; | |
esac | |
# xterm title settings | |
case $TERM in | |
xterm*|rxvt|Eterm|eterm) | |
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' | |
export PROMPT_COMMAND | |
;; | |
screen) | |
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' | |
export PROMPT_COMMAND | |
;; | |
esac | |
LONG_ARGS=0 | |
# enable color support of ls and also add handy aliases | |
if `which dircolors >/dev/null 2>&1`; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
if [[ $(man ls 2>&1 | cat 2>&1 | grep "\-\-color" 2>&1 | wc -l 2>&1) >=1 ]]; then | |
LONG_ARGS=1 | |
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" | |
alias ls='ls --color=auto --ignore-backups --time-style="+%x %X"' | |
else | |
LS_COLORS="ow=01;90:di=01;90" | |
export LS_COLORS | |
LSCOLORS="ow=01;90:di=01;90" | |
export LSCOLORS | |
alias ls='ls -G' | |
fi | |
fi | |
alias profileme="history | cut -f 2- -d \"]\" | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr" | |
alias IPAddress="ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print \$2}' | cut -f1 -d'/'" | |
alias df="df -Tm" | |
alias cp="cp -i" | |
alias cpr="cp -r" | |
alias mv="mv -i" | |
alias mkdir="mkdir -p" | |
alias ll="ls -lA" | |
alias lt="ls -lhStrA" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias ......="cd ../../../../.." | |
alias .......="cd ../../../../../.." | |
alias ........="cd ../../../../../../.." | |
alias .........="cd ../../../../../../../.." | |
alias ..........="cd ../../../../../../../../.." | |
alias ...........="cd ../../../../../../../../../.." | |
alias ............="cd ../../../../../../../../../../.." | |
alias .............="cd ../../../../../../../../../../../.." | |
alias ..............="cd ../../../../../../../../../../../../.." | |
export HISTFILESIZE=1000000000 | |
export HISTSIZE=2000000 | |
for file in ~/.{path,bash_functions,bash_prompt,exports,bash_aliases,extra,bash_custom,bash_local}; do | |
[ -r "$file" ] && source "$file" | |
done | |
unset file | |
# Enable some Bash 4 features when possible: | |
for option in histappend checkwinsize autocd globstar cmdhist checkhash lithist extglob ; do | |
shopt -s "$option" 2> /dev/null | |
done | |
##### PATH ##################################################################### | |
paths="${HOME}/bin" | |
paths="${paths} /sbin" | |
paths="${paths} /bin" | |
paths="${paths} /usr/local/bin" | |
paths="${paths} /usr/sbin" | |
paths="${paths} /usr/bin" | |
paths="${paths} /usr/games" | |
PATHS=$(echo "/usr/local/opt/coreutils/libexec/gnubin /usr/local/sbin/sbin /bin /usr/local/bin /usr/sbin /usr/bin /usr/games") | |
for i in "${PATHS[@]}"; do | |
if `echo $PATH | egrep "$i"'(\:|$)'`; then | |
continue | |
fi | |
if [ -d "$i" ]; then | |
PATH="$PATH:$i" | |
fi | |
done | |
PATH=`echo $PATH | sed -e 's/^\://' -e 's/\:\:/:/g'` | |
export PATH | |
##### Prompt ############################################################## | |
BASECOLOR=$FYEL | |
USERCOLOR=$FBLE | |
HOSTCOLOR=$FMAG | |
PWDCOLOR=$FBLE | |
if [ $(whoami) == "root" ]; then | |
USERCOLOR=$BRED | |
fi | |
PS1="$HC$BASECOLOR[ $USERCOLOR\u$RS$HC@$HOSTCOLOR\H$BASECOLOR: $PWDCOLOR\w $BASECOLOR]\\$ $RS" | |
PS2="$HC$BASECOLOR> $RS" | |
# Check for interactive bash and that we haven't already been sourced. | |
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return | |
# Check for recent enough version of bash. | |
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} | |
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then | |
if ! shopt -oq posix; then | |
if shopt -q progcomp && [ -r /usr/local/Cellar/bash-completion/1.3/etc/bash_completion ]; then | |
. /usr/local/Cellar/bash-completion/1.3/etc/bash_completion | |
elif [ -f /usr/local/share/bash-completion/bash_completion ]; then | |
. /usr/local/share/bash-completion/bash_completion | |
elif [ -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 | |
fi | |
unset bash bmajor bminor | |
[ -r "~/.bash_completion" ] && source "~/.bash_completion" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment