Don't like ads? PRO users don't see any ads ;-)
Guest

bashrc Template with Useful Features

By: yuval on Sep 24th, 2012  |  syntax: Bash  |  size: 6.84 KB  |  hits: 78  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. #
  5. #                    ..__...__.........._____.
  6. #                    _/  |_|__|._______/  ___\
  7. #                    \   __\  |/  ___/\   __\.
  8. #                    .|  |.|  |\___ \..|  |...
  9. #                    .|__|.|__/____  >.|__|...
  10. #                    ..............\/.........
  11. #
  12. #                     Useful Bashrc Template
  13. #
  14. #     For all functions to be operational you need to get
  15. #   elinks, wikipedia2tex and macchanger using apt-get. Create  
  16. #    a backup of your ~/.bashrc and then replace it with
  17. #     this script to add a bit for functionality.
  18. #
  19. #
  20. #       Build by Yuval (tisf) Nativ from See-Security Group
  21. #                  http://www.see-security.com
  22. #                 https://avtacha.wordpress.com
  23. #
  24. #
  25. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28.  
  29.  
  30. # Initializing Colors
  31.     DULL=0
  32.     BRIGHT=1
  33.     FG_BLACK=30
  34.     FG_RED=31
  35.     FG_GREEN=32
  36.     FG_YELLOW=33
  37.     FG_BLUE=34
  38.     FG_VIOLET=35
  39.     FG_CYAN=36
  40.     FG_WHITE=37
  41.     FG_NULL=00
  42.     BG_BLACK=40
  43.     BG_RED=41
  44.     BG_GREEN=42
  45.     BG_YELLOW=43
  46.     BG_BLUE=44
  47.     BG_VIOLET=45
  48.     BG_CYAN=46
  49.     BG_WHITE=47
  50.     BG_NULL=00
  51.     ESC="\033"
  52.     NORMAL="\[$ESC[m\]"
  53.     RESET="\[$ESC[${DULL};${FG_WHITE};${BG_NULL}m\]"
  54.     BLACK="\[$ESC[${DULL};${FG_BLACK}m\]"
  55.     RED="\[$ESC[${DULL};${FG_RED}m\]"
  56.     GREEN="\[$ESC[${DULL};${FG_GREEN}m\]"
  57.     YELLOW="\[$ESC[${DULL};${FG_YELLOW}m\]"
  58.     BLUE="\[$ESC[${DULL};${FG_BLUE}m\]"
  59.     VIOLET="\[$ESC[${DULL};${FG_VIOLET}m\]"
  60.     CYAN="\[$ESC[${DULL};${FG_CYAN}m\]"
  61.     WHITE="\[$ESC[${DULL};${FG_WHITE}m\]"
  62.     BRIGHT_BLACK="\[$ESC[${BRIGHT};${FG_BLACK}m\]"
  63.     BRIGHT_RED="\[$ESC[${BRIGHT};${FG_RED}m\]"
  64.     BRIGHT_GREEN="\[$ESC[${BRIGHT};${FG_GREEN}m\]"
  65.     BRIGHT_YELLOW="\[$ESC[${BRIGHT};${FG_YELLOW}m\]"
  66.     BRIGHT_BLUE="\[$ESC[${BRIGHT};${FG_BLUE}m\]"
  67.     BRIGHT_VIOLET="\[$ESC[${BRIGHT};${FG_VIOLET}m\]"
  68.     BRIGHT_CYAN="\[$ESC[${BRIGHT};${FG_CYAN}m\]"
  69.     BRIGHT_WHITE="\[$ESC[${BRIGHT};${FG_WHITE}m\]"
  70.     REV_CYAN="\[$ESC[${DULL};${BG_WHITE};${BG_CYAN}m\]"
  71.     REV_RED="\[$ESC[${DULL};${FG_YELLOW}; ${BG_RED}m\]"
  72.     PROMPT_COMMAND='export ERR=$?'
  73.  
  74.  
  75. # Configuring Basic Settings
  76. # Touch only if you understand
  77.  
  78.     [ -z "$PS1" ] && return
  79.     HISTCONTROL=ignoreboth
  80.     shopt -s histappend
  81.     HISTSIZE=1000
  82.     HISTFILESIZE=2000
  83.     shopt -s checkwinsize
  84.     [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  85.  
  86.     if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  87.         debian_chroot=$(cat /etc/debian_chroot)
  88.     fi
  89.  
  90.     case "$TERM" in
  91.         xterm-color) color_prompt=yes;;
  92.     esac
  93.  
  94.     if [ -n "$force_color_prompt" ]; then
  95.         if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  96.         color_prompt=yes
  97.         else
  98.         color_prompt=
  99.         fi
  100.     fi
  101.  
  102.     if [ -f ~/.bash_aliases ]; then
  103.         . ~/.bash_aliases
  104.     fi
  105.  
  106.     if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
  107.         . /etc/bash_completion
  108.     fi
  109.  
  110. PATH=$PATH:$HOME/.rvm/bin
  111.  
  112. # Configure PS1
  113.    
  114.     if [ "$color_prompt" = yes ]; then
  115.         PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  116.     else
  117.         PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  118.     fi
  119.     unset color_prompt force_color_prompt
  120.  
  121.     case "$TERM" in
  122.     xterm*|rxvt*)
  123.         PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  124.         ;;
  125.     *)
  126.         ;;
  127.     esac
  128.  
  129. # Fun aliases
  130.  
  131.     if [ -x /usr/bin/dircolors ]; then
  132.         test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  133.         alias ls='ls --color=auto'
  134.         alias grep='grep --color=auto'
  135.         alias fgrep='fgrep --color=auto'
  136.         alias egrep='egrep --color=auto'
  137.     fi
  138.  
  139.     alias ll='ls -alF'
  140.     alias la='ls -A'
  141.     alias l='ls -CF'
  142.     alias wifires='sudo /etc/init.d/network-manager restart'
  143.     alias ps='ps auxf'
  144.     alias home='cd ~'
  145.     alias openports='netstat -nape --inet'
  146.     alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 '
  147.     alias expdb='echo "cat  //title/text()" | xmllint --shell http://www.exploit-db.com/rss.xml'
  148.     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$//'\'')"'
  149.  
  150. # A bit more complex aliases
  151.     events ()
  152.     {
  153.         echo ""
  154.         echo "--------------- Events on this day ---------------"
  155.         mon=`date +%B`
  156.         day=`date +%d`
  157.         wikipedia2text -b elinks "$day $mon" | grep -A 30 "^Events"
  158.         echo "---------------------------------------------------"
  159.         echo ""
  160.     }
  161.  
  162.     deaths ()
  163.     {
  164.         echo ""
  165.         echo "--------------- Deaths on this day ---------------"
  166.         mon=`date +%B`
  167.         day=`date +%d`
  168.         wikipedia2text -b elinks "$day $mon" | grep -A 30 "^Deaths"
  169.         echo "---------------------------------------------------"
  170.         echo ""
  171.     }
  172.  
  173.     births ()
  174.     {
  175.         echo ""
  176.         echo "--------------- Births on this day ---------------"
  177.         mon=`date +%B`
  178.         day=`date +%d`
  179.         wikipedia2text -b elinks "$day $mon" | grep -A 30 "^Births"
  180.         echo "---------------------------------------------------"
  181.         echo ""
  182.     }
  183.  
  184.     netinfo ()
  185.     {
  186.         echo ""
  187.         echo "--------------- Network Information ---------------"
  188.         /sbin/ifconfig | awk /'inet addr/ {print $2}'
  189.         /sbin/ifconfig | awk /'Bcast/ {print $3}'
  190.         /sbin/ifconfig | awk /'inet addr/ {print $4}'
  191.         /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
  192.         echo "---------------------------------------------------"
  193.         echo ""
  194.     }
  195.  
  196.     hideme ()
  197.     {
  198.         echo ""
  199.         echo "--------------- Network Information ---------------"
  200.         /sbin/ifconfig eth0 | awk /'HWaddr/ {print "eth0 MAC:",$5}'
  201.         /sbin/ifconfig wlan0 | awk /'HWaddr/ {print "wlan0 MAC:",$5}'
  202.         sudo ifconfig eth0 down
  203.         sudo ifconfig wlan0 down
  204.         sudo macchanger -r eth0
  205.         sudo macchanger -r wlan0
  206.         /sbin/ifconfig eth0 | awk /'HWaddr/ {print "eth0 New MAC:",$5}'
  207.         /sbin/ifconfig wlan0 | awk /'HWaddr/ {print "wlan0 New MAC:",$5}'
  208.         echo "---------------------------------------------------"
  209.         echo ""
  210.     }
  211.    
  212.         extip ()
  213.         {
  214.                 mkdir blabla
  215.                 cd blabla
  216.                 wget -q http://www.showmemyip.com/
  217.                 cat index.html | grep '<span id="IPAddress"' | awk '{print $2}' | sed "s/.......$//" | cut -c16-99
  218.                 rm index.html
  219.                 cd ..
  220.                 rmdir blabla
  221.         }