SHARE
TWEET

.bashrc

a guest Aug 22nd, 2015 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # /etc/bash.bashrc
  3. #
  4. # https://wiki.archlinux.org/index.php/Color_Bash_Prompt
  5. #
  6. # This file is sourced by all *interactive* bash shells on startup,
  7. # including some apparently interactive shells such as scp and rcp
  8. # that can't tolerate any output. So make sure this doesn't display
  9. # anything or bad things will happen !
  10.  
  11. # Test for an interactive shell. There is no need to set anything
  12. # past this point for scp and rcp, and it's important to refrain from
  13. # outputting anything in those cases.
  14.  
  15. # If not running interactively, don't do anything!
  16. [[ $- != *i* ]] && return
  17.  
  18. # Bash won't get SIGWINCH if another process is in the foreground.
  19. # Enable checkwinsize so that bash will check the terminal size when
  20. # it regains control and update the values of LINES and COLUMNS.
  21. # http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
  22. shopt -s checkwinsize
  23.  
  24. # Enable history appending instead of overwriting.
  25. shopt -s histappend
  26.  
  27. # don't put duplicate lines in the history. See bash(1) for more options
  28. # ... or force ignoredups and ignorespace
  29. HISTCONTROL=ignoredups:ignorespace
  30.  
  31. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  32. HISTSIZE=1000
  33. HISTFILESIZE=2000
  34.  
  35. # Set colorful PS1 only on colorful terminals.
  36. # dircolors --print-database uses its own built-in database
  37. # instead of using /etc/DIR_COLORS. Try to use the external file
  38. # first to take advantage of user additions. Use internal bash
  39. # globbing instead of external grep binary.
  40.  
  41. # sanitize TERM:
  42. safe_term=${TERM//[^[:alnum:]]/?}
  43. match_lhs=""
  44.  
  45. [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
  46. [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
  47. [[ -z ${match_lhs} ]] \
  48.         && type -P dircolors >/dev/null \
  49.         && match_lhs=$(dircolors --print-database)
  50.  
  51. if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then
  52.         # we have colors :-)
  53.  
  54.         # Enable colors for ls, etc. Prefer ~/.dir_colors
  55.         if type -P dircolors >/dev/null ; then
  56.                 if [[ -f ~/.dir_colors ]] ; then
  57.                         eval $(dircolors -b ~/.dir_colors)
  58.                 elif [[ -f /etc/DIR_COLORS ]] ; then
  59.                         eval $(dircolors -b /etc/DIR_COLORS)
  60.                 fi
  61.         fi
  62.  
  63.     # enable color support of ls and also add handy aliases
  64.     alias ls='ls --color=auto'
  65.     alias grep='grep --color=auto'
  66.     alias fgrep='fgrep --color=auto'
  67.     alias egrep='egrep --color=auto'
  68. fi
  69.  
  70. PS2="> "
  71. PS3="> "
  72. PS4="+ "
  73.  
  74. # Try to keep environment pollution down, EPA loves us.
  75. unset safe_term match_lhs
  76.  
  77. # custom Bash alias
  78. alias ll='ls -alF'
  79. alias la='ls -A'
  80. alias l='ls -CF'
  81. alias murder='kill -9'
  82. # Add an "alert" alias for long running commands.  Use: sleep 10; alert
  83. 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$//'\'')"'
  84. alias ..="cd .."
  85. alias ...="cd ../.."
  86. alias ....="cd ../../.."
  87. alias .....="cd ../../../.."
  88. alias list="ls -a"
  89. alias man="man -a"
  90. alias delete="rm -iv"
  91. alias rm="rm -iv"
  92. alias trash="rm -rf ~/.local/share/Trash/"
  93. alias :q="exit"
  94. alias home="cd ~"
  95. alias unmount="umount"
  96. alias clear="reset"
  97. alias cdopen="eject"
  98. alias cdclose="eject -t"
  99. alias msg="notify-send"
  100. alias shutdown="sudo shutdown -h now"
  101. alias snano="sudo nano"
  102. alias back="cd $OLDPWD"
  103. alias root="sudo su"
  104. alias ip="ifconfig"
  105. alias lynx="(lynx -accept_all_cookies)"
  106. alias hist='more ~/.bash_history | grep '
  107.  
  108. # custom apt-get alias
  109. alias install="sudo apt-fast install"
  110. alias uninstall='sudo apt-fast remove'
  111. alias reinstall='sudo apt-fast --reinstall install'
  112. alias purge="sudo apt-fast remove --purge"
  113. alias clean="sudo apt-fast autoclean"
  114. alias update="sudo apt-fast update"
  115. alias upgrade="sudo apt-fast upgrade"
  116. alias autoremove="sudo apt-fast autoremove"
  117. alias addrepo='sudo add-apt-repository'
  118. alias search="sudo apt-cache search"
  119. alias searchIn="apt-file search"
  120.  
  121. extract () {
  122.      if [ -f $1 ] ; then
  123.          case $1 in
  124.              *.tar.bz2)   tar xjf $1;;
  125.              *.tar.gz)    tar xzf $1;;
  126.              *.bz2)       bunzip2 $1;;
  127.              *.rar)       rar x $1;;
  128.              *.gz)        gunzip $1;;
  129.              *.tar)       tar xf $1;;
  130.              *.tbz2)      tar xjf $1;;
  131.              *.tgz)       tar xzf $1;;
  132.              *.zip)       unzip $1;;
  133.              *.Z)         uncompress $1;;
  134.              *.7z)        7z x $1;;
  135.              *)           echo "'$1' cannot be extracted via extract()";;
  136.          esac
  137.      else
  138.          echo "'$1' is not a valid file"
  139.      fi
  140. }
  141.  
  142. #netinfo - shows network information for your system
  143. function netinfo() {
  144.         echo "--------------- Network Information ---------------"
  145.         /sbin/ifconfig | awk /'inet addr/ {print $2}'
  146.         /sbin/ifconfig | awk /'Bcast/ {print $3}'
  147.         /sbin/ifconfig | awk /'inet addr/ {print $4}'
  148.         /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
  149.         myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
  150.         echo "${myip}"
  151.         echo "---------------------------------------------------"
  152. }
  153.  
  154. # Check to see if a site is down for everyone or just me
  155. function downforme() {
  156.         RED='\e[1;31m'
  157.         GREEN='\e[1;32m'
  158.         YELLOW='\e[1;33m'
  159.         NC='\e[0m'
  160.         if [ $# = 0 ]
  161.         then
  162.                 echo -e "${YELLOW}usage:${NC} downforme website_url"
  163.         else
  164.                 JUSTYOUARRAY=(`lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"`)
  165.                 if [ ${#JUSTYOUARRAY} != 0 ]
  166.                 then
  167.                         echo -e "${RED}It's just you. \n${NC}$1 is up."
  168.                 else
  169.                         echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here."
  170.                 fi
  171.         fi
  172. }
  173.  
  174. # cp with progress bar
  175. function cp_pro() {
  176.         if [ `echo "$2" | grep ".*\/$"` ]
  177.         then
  178.                 pv "$1" > "$2""$1"
  179.         else
  180.                 pv "$1" > "$2"/"$1"
  181.         fi
  182. }
  183.  
  184. # mkdir and cd into it
  185. function mkdir_go() {
  186.     mkdir $1 && cd $1
  187. }
  188.  
  189. #bu - Back Up a file. Usage "bu filename.txt"
  190. function bu() {
  191.     cp $1 ${1}-`date +%Y%m%d%H%M`.backup;
  192. }
  193.  
  194. ##################################################
  195. # Fancy PWD display function
  196. ##################################################
  197. # The home directory (HOME) is replaced with a ~
  198. # The last pwdmaxlen characters of the PWD are displayed
  199. # Leading partial directory names are striped off
  200. # /home/me/stuff                -> ~/stuff                      if USER=me
  201. # /usr/share/big_dir_name       -> ../share/big_dir_name        if pwdmaxlen=20
  202. ##################################################
  203. parse_pwd() {
  204.         # How many characters of the $PWD should be kept
  205.         local pwdmaxlen=25
  206.         # Indicate that there has been dir truncation
  207.         local trunc_symbol=".."
  208.         local dir=${PWD##*/}
  209.         pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
  210.         NEW_PWD=${PWD/#$HOME/\~}
  211.         local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
  212.         if [ ${pwdoffset} -gt "0" ]
  213.         then
  214.                 NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
  215.                 NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
  216.         fi
  217. }
  218.  
  219. function load_out() {
  220.   echo -n "$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g")"
  221. }
  222.  
  223. function load_color() {
  224.  gray=0
  225.  red=1
  226.  green=2
  227.  yellow=3
  228.  blue=4
  229.  magenta=5
  230.  cyan=6
  231.  white=7
  232.  
  233.  # Colour progression is important ...
  234.  #   bold gray -> bold green -> bold yellow -> bold red ->
  235.  #   black on red -> bold white on red
  236.  #
  237.  # Then we have to choose the values at which the colours switch, with
  238.  # anything past yellow being pretty important.
  239.  
  240.  tmp=$(echo $(load_out)*100 | bc)
  241.  let load100=${tmp%.*}
  242.  
  243.  if [ ${load100} -lt 70 ]
  244.  then
  245.    tput bold ; tput setaf ${gray}
  246.  elif [ ${load100} -ge 70 ] && [ ${load100} -lt 120 ]
  247.  then
  248.    tput bold ; tput setaf ${green}
  249.  elif [ ${load100} -ge 120 ] && [ ${load100} -lt 200 ]
  250.  then
  251.    tput bold ; tput setaf ${yellow}
  252.  elif [ ${load100} -ge 200 ] && [ ${load100} -lt 300 ]
  253.  then
  254.    tput bold ; tput setaf ${red}
  255.  elif [ ${load100} -ge 300 ] && [ ${load100} -lt 500 ]
  256.  then
  257.    tput setaf ${gray} ; tput setab ${red}
  258.  else
  259.    tput bold ; tput setaf ${white} ; tput setab ${red}
  260.  fi
  261. }
  262.  
  263. bash_prompt() {
  264.         case $TERM in
  265.                 xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
  266.                         local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
  267.                         #local TITLEBAR=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
  268.                         #local TITLEBAR=\[\ek\e\\\]\[\ek\W\e\\\]
  269.                         ;;
  270.                 screen)
  271.                     #local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
  272.                     #local TITLEBAR=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
  273.                     local TITLEBAR=\[\ek\e\\\]\[\ek\W\e\\\]
  274.                     ;;
  275.                 *)
  276.                         local TITLEBAR=""
  277.                         ;;
  278.         esac
  279.         local NONE="\[\033[0m\]"        # unsets color to term's fg color
  280.  
  281.         # regular colors
  282.         local K="\[\033[0;30m\]"        # grey
  283.         local R="\[\033[0;31m\]"        # red
  284.         local G="\[\033[0;32m\]"        # green
  285.         local Y="\[\033[0;33m\]"        # yellow
  286.         local B="\[\033[0;34m\]"        # blue
  287.         local M="\[\033[0;35m\]"        # magenta
  288.         local C="\[\033[0;36m\]"        # cyan
  289.         local W="\[\033[0;37m\]"        # white
  290.  
  291.         # emphasized (bolded) colors
  292.         local EMK="\[\033[1;30m\]"
  293.         local EMR="\[\033[1;31m\]"
  294.         local EMG="\[\033[1;32m\]"
  295.         local EMY="\[\033[1;33m\]"
  296.         local EMB="\[\033[1;34m\]"
  297.         local EMM="\[\033[1;35m\]"
  298.         local EMC="\[\033[1;36m\]"
  299.         local EMW="\[\033[1;37m\]"
  300.  
  301.         # background colors
  302.         local BGK="\[\033[40m\]"
  303.         local BGR="\[\033[41m\]"
  304.         local BGG="\[\033[42m\]"
  305.         local BGY="\[\033[43m\]"
  306.         local BGB="\[\033[44m\]"
  307.         local BGM="\[\033[45m\]"
  308.         local BGC="\[\033[46m\]"
  309.         local BGW="\[\033[47m\]"
  310.  
  311.         local UC=$B                             # user's color
  312.         [ $UID -eq "0" ] && UC=$R       # root's color
  313.  
  314.     USER_INFO="${UC}\u${EMK}@${UC}\h"
  315.     DATE="\$(date +'%-I:%M %p')"
  316.     DATE_TOP_RIGHT='\[\033[s\]\[\033[1;\$((COLUMNS-4))f\]\$(date +%H:%M)\[\033[u\]'
  317.     YAY_NAY="\$(if [[ \$? == 0 ]]; then echo \"${G}\$?\"; else echo \"${R}\$?\"; fi)"
  318.     FREE_MEM="${R}"$((`sed -nu "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"${EMK}/${G}"$((`sed -nu "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024))MB""
  319.     SYS_LOAD="\$(cut -c 1-14 /proc/loadavg)"
  320.     FOLDER_INFO="\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -lah | grep -m 1 total | sed 's/total //')b"
  321.  
  322.     # ┌─┬─┐
  323.     # ├─┼─┤
  324.     # └─┴─┘
  325.     # ▒ ° ±
  326.  
  327.     # My standard custom shell:
  328.     # ┌─(uminded@uminded-Inspiron-1545)─(10:05 AM)
  329.     # ├─(~\Downloads)─(12 files, 248Kb)
  330.     # ├─(✓ 0)─(0.42 0.18 0.15)─(445/2467MB)
  331.     # └─>
  332.  
  333.     export PS1="\n${EMK}┌─(${USER_INFO}${EMK})─(${B}\${NEW_PWD}${EMK})─(${B}${FOLDER_INFO}${EMK})\n"
  334.     export PS1="$PS1${EMK}└─(${YAY_NAY}${EMK})─> ${NONE}"
  335. }
  336.  
  337. PROMPT_COMMAND=parse_pwd
  338. bash_prompt
  339. unset bash_prompt
  340.  
  341. # Handy Apps To Install:
  342. #most - color man pages
  343. export MANPAGER="/usr/bin/most -s"
  344. export ANTARES_INSTALL_DIR=~/.antares
  345. export PATH="$PATH:/home/uminded/stlink"
  346. export PATH="$PATH:/home/uminded/gcc-arm-none-eabi/bin"
  347.  
  348. # added by Anaconda 2.0.1 installer
  349. export PATH="/home/uminded/anaconda/bin:$PATH"
  350.  
  351. # load byobu-launcher with session choice and tmux on prompt load
  352. _byobu_sourced=1 . /usr/bin/byobu-launch
  353. export TERM=screen-256color
  354. alias tmux="tmux -2"
  355.  
  356. # load solarized 256 dark color pallet for ls
  357. eval `dircolors ~/.dircolors.256dark`
  358.  
  359. # Files needed to be installed for this .bashrc to work
  360. # sudo add-apt-repository ppa:apt-fast/stable
  361. # sudo apt-get update
  362. # sudo apt-get install apt-fast apt-file nano lynx more less tmux byobu
  363.  
  364. # tmux install notes
  365. # solarizer: https://github.com/seebi/tmux-colors-solarized just copy 256 pallet to .tmux.conf
  366.  
  367. # vi install notes
  368. # vim plugins and highlighters: https://github.com/amix/vimrc
  369.  
  370. # shell notes
  371. # dircolors: https://github.com/seebi/dircolors-solarized
  372.  
  373. # gnome-terminal notes
  374. # solerized pallet: https://github.com/Anthony25/gnome-terminal-colors-solarized
  375. # After select the background to be slightly darker than the tmux status bar.
RAW Paste Data
Want to get better at Bash?
Learn to code Bash in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top