
#___________           __      _______    .__                __           
#\__    ___/   ____   |  | __  \      \   |__|   ____       |__| _____    
#  |    |    _/ __ \  |  |/ /  /   |   \  |  |  /    \      |  | \__  \   
#  |    |    \  ___/  |    <  /    |    \ |  | |   |  \     |  |  / __ \_ 
#  |____|     \___  > |__|_ \ \____|__  / |__| |___|  / /\__|  | (____  / 
#                 \/       \/         \/            \/  \______|      \/  
#                                                                         
#   _____    .__    .__                                      
#  /  _  \   |  |   |__| _____      ______ _______    ____   
# /  /_\  \  |  |   |  | \__  \    /  ___/ \_  __ \ _/ ___\  
#/    |    \ |  |__ |  |  / __ \_  \___ \   |  | \/ \  \___  
#\____|__  / |____/ |__| (____  / /____  >  |__|     \___  > 
#        \/                   \/       \/                \/  

# Author - TekNinja-Kevin Tangereen Spidermankevin78@gmail.com 
# Last Update October 23th 2017
# License - © 2017 WTFPL - http://www.wtfpl.net/ 
#---------Bash Color Code {{{
#------------------------------------------------------
# LINK: https://wiki.archlinux.org/index.php?title=Bash/Prompt_customization&oldid=419076#List_of_colors_for_prompt_and_Bash

# Reset
Color_Off='\e[0m'       # Text Reset

# Regular Colors
Black='\e[0;30m'        # Black
Red='\e[0;31m'          # Red
Green='\e[0;32m'        # Green
Yellow='\e[0;33m'       # Yellow
Blue='\e[0;34m'         # Blue
Purple='\e[0;35m'       # Purple
Cyan='\e[0;36m'         # Cyan
White='\e[0;37m'        # White

# Bold
BBlack='\e[1;30m'       # Black
BRed='\e[1;31m'         # Red
BGreen='\e[1;32m'       # Green
BYellow='\e[1;33m'      # Yellow
BBlue='\e[1;34m'        # Blue
BPurple='\e[1;35m'      # Purple
BCyan='\e[1;36m'        # Cyan
BWhite='\e[1;37m'       # White

# Underline
UBlack='\e[4;30m'       # Black
URed='\e[4;31m'         # Red
UGreen='\e[4;32m'       # Green
UYellow='\e[4;33m'      # Yellow
UBlue='\e[4;34m'        # Blue
UPurple='\e[4;35m'      # Purple
UCyan='\e[4;36m'        # Cyan
UWhite='\e[4;37m'       # White

# Background
On_Black='\e[40m'       # Black
On_Red='\e[41m'         # Red
On_Green='\e[42m'       # Green
On_Yellow='\e[43m'      # Yellow
On_Blue='\e[44m'        # Blue
On_Purple='\e[45m'      # Purple
On_Cyan='\e[46m'        # Cyan
On_White='\e[47m'       # White

# High Intensity
IBlack='\e[0;90m'       # Black
IRed='\e[0;91m'         # Red
IGreen='\e[0;92m'       # Green
IYellow='\e[0;93m'      # Yellow
IBlue='\e[0;94m'        # Blue
IPurple='\e[0;95m'      # Purple
ICyan='\e[0;96m'        # Cyan
IWhite='\e[0;97m'       # White

# Bold High Intensity
BIBlack='\e[1;90m'      # Black
BIRed='\e[1;91m'        # Red
BIGreen='\e[1;92m'      # Green
BIYellow='\e[1;93m'     # Yellow
BIBlue='\e[1;94m'       # Blue
BIPurple='\e[1;95m'     # Purple
BICyan='\e[1;96m'       # Cyan
BIWhite='\e[1;97m'      # White

# High Intensity backgrounds
On_IBlack='\e[0;100m'   # Black
On_IRed='\e[0;101m'     # Red
On_IGreen='\e[0;102m'   # Green
On_IYellow='\e[0;103m'  # Yellow
On_IBlue='\e[0;104m'    # Blue
On_IPurple='\e[10;95m'  # Purple
On_ICyan='\e[0;106m'    # Cyan
On_IWhite='\e[0;107m'   # White

# }}}
#-------- Configurations {{{
###########################################################
#===================Quick Configurations==================#
###########################################################
# one word commands to edit configertion files

#-----------------System Files------------------#
cfg-fstab() { sudo $EDITOR /etc/fstab ;}
cfg-grub() { sudo $EDITOR /etc/default/grub ;}
cfg-inputrc() { $EDITOR ~/.inputrc ;}
cfg-xresources() { $EDITOR ~/.Xresources ;}
cfg-sudoers() { sudo $EDITOR /etc/sudoers ;}

#-------------------Shells----------------------#
cfg-aliasrc() { $EDITOR ~/.aliasrc ;}
cfg-zshrc() { $EDITOR ~/.zshrc ;}
cfg-profile() { $EDITOR ~/.profile ;}
cfg-bashrc() { $EDITOR ~/.bashrc ;}
#------------------Curser-----------------------#
cfg-cursor() { $EDITOR ~/.icons/default/index.theme ;}
cfg-cursor-list() { ls ~/.icons ;}
#----------------Editor Configs-----------------#
cfg-vimrc() { $EDITOR ~/.vimrc ;}
cfg-nanorc() { $EDITOR ~/.nanorc;}
cfg-emacs() { $EDITOR ~/.emacs ;}
#--------------------i3 config-------------------#
cfg-i3wm() { $EDITOR ~/.i3/config ;}
#----------Music Player Configs------------------#
cfg-mpd() { $EDITOR ~/.mpd/mpd.conf ;}
cfg-mplayer() { $EDITOR ~/.mplayer/config ;}
cfg-mpv() { $EDITOR ~/.config/mpv/input.conf ;}
cfg-ncmpcpp() { $EDITOR ~/.ncmpcpp/config ;}
cfg-ncmpcpp-bindings() { $EDITOR ~/.ncmpcpp/bindings ;}
cfg-pulseaudio() { sudo $EDITOR /etc/pulse/default.pa ;}
cfg-mocp() { $EDITOR ~/.moc/config ;}
#--------E-Mail & News---------------------------#
cfg-muttrc() { $EDITOR ~/.muttrc ;}
cfg-newsbeuter() { $EDITOR ~/.newsbeuter/config ;}
cfg-newsbeuter-queue() { $EDITOR ~/.newsbeuter/queue ;}
cfg-newsbeuter-urls() { $EDITOR ~/.newsbeuter/urls ;}
#----------Ranger & MC Configs-------------------#
cfg-ranger() { $EDITOR ~/.config/ranger/rc.conf ;}
cfg-ranger-rifle() { $EDITOR ~/.config/ranger/rifle.conf ;}
cfg-ranger-commands() { $EDITOR ~/.config/ranger/commands.py ;}
cfg-mc() { $EDITOR ~/.config/mc/ini ;}
#------------------------------------------------#
#----------------Networking Configs--------------# 
cfg-samba() { sudo $EDITOR /etc/samba/smb.conf ;}
cfg-ssh-client() { sudo $EDITOR /etc/ssh/ssh_config ;}
cfg-ssh-daemon() { sudo $EDITOR /etc/ssh/sshd_config ;}
cfg-blocklist() { $EDITOR ~/.scripts/blocklist.sh ;}
cfg-hosts() { sudo $EDITOR /etc/hosts ;}
#------------------------------------------------#
cfg-w3m() { $EDITOR ~/.w3m/config ;}
cfg-w3m-keymap() { $EDITOR ~/.w3m/keymap ;}
cfg-w3m-urimethodmap() { $EDITOR ~/.w3m/urimethodmap ;}
#--------------------Other----------------------#
cfg-abookrc() { $EDITOR ~/.abook/abookrc ;}
cfg-mailcap() { $EDITOR ~/.mailcap ;}
cfg-comix() { $EDITOR ~/.config/comix/keybindings.conf ;}
cfg-pastebinit() { $EDITOR ~/.pastebinit.xml ;}
cfg-tmuxrc() { $EDITOR ~/.tmux.conf ;}
#---------------------------------------------------------------#
#========================Reload Configs=========================#
rxr() { xrdb -load ~/.Xresources ;}               #Reload Xresources
#---------------------------------------------------------------#
#END OF SECTION}}}
#---------File System Aliases{{{
#---------------------don't have to type cd to go back--------#
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
#-------------------------------------------------------------#
#---------------------listing files---------------------------#
alias dir='dir --color=auto'                  #good ol dir for C/PM & MsDos
alias vdir='vdir --color=auto'
alias ls='ls --color=always --human-readable --group-directories-first --classify'
# List all files colorized in long format, including dot files
alias la="ls -lFh"                # List all Files in long format.
alias lsd="ls -lF | grep '^d'"    # List only directories
alias lsf='ls -p | grep -v '/$''  # List files Only
alias lx='ls -lXB'                # Sort file by extinsion
alias lk='ls -lSr'                # Sort By Size
alias lc='ls -lcr'                # Sort by Change Time
alias lu='ls -lur'                # Sort by access time
alias lr='ls -l | less'           # Recursive ls
alias lt='ls -ltr'                # Sort by date
alias lm='ls -al |most'           # Ls + most
#My File Selector Uses pick and riffle select and open files
alias lsp='ls | pick | xargs riffle' 
#------------------------------------------------------------#
#--------------------- Shortcuts-----------------------------#
alias p="cd ~/projects"                         #Projects folder
alias scripts='cd ~/scripts'                    #scripts
alias home='cd ~/'                              #go home
alias docs='cd ~/Documents'                     #docs
alias downloads='cd ~/Downloads'                #Downloads
alias books='cd /media/Shared_Docs/Books'
alias pictures='cd ~/Pictures'
alias torrents='cd ~/Torrents'
alias videos='cd ~/Videos'
alias wallpaper='cd ~/Pictures/Wallpaper'
alias screenshots='cd ~/Pictures/Screenshots'
alias music='cd ~/Music'
alias journal='edit ~/Documents/My_Journal.txt'
alias Vynel_Catalog='scim HOME$/Spreed_Sheets/MusicCollection.sc' 
#}}}
#---------Program and command aliases{{{
#------------------------------------------------------------#
#--------------------Language aliases------------------------#
alias rb='ruby'
alias py='python'
alias ipy='ipython'
alias jj="java jar-"
#------------------------------------------------------------#
#---------------- Directory Manepulation---------------------#
alias md='mkdir -p'
alias rd='rmdir'
#------------------------------------------------------------#
#----------------------Vim Like Exit-------------------------#
alias :q='exit'
alias q='exit'
#------------------------------------------------------------#
#--------------------Safer Commands--------------------------#
alias rm='rm -i -v'
alias cp='cp -i -v'
alias mv='mv -i -v'
alias du='du -kh'
alias df='df -kTh'
alias mkdir='mkdir -v -p'
alias rmdir='rmdir -v'
alias ln='ln -v -i'
alias chmod='chmod -c'
alias chown='chown -c'
#-------------------------------------------------------------#
#-----------------One Letter Short-Cuts-----------------------#
alias g="git"
alias r='ranger'
alias e='vim'
alias v='vim'
alias h="hh"
alias j="jobs"
alias f='ranger:'
alias t='tail -f'
#-------------------------------------------------------------#
#------------------Ms Dos Commands For unix-------------------#
alias copy='cp'                      #copy File
alias del='rm'                       #Delete File
alias ren='mv'                       #Rename file
#-------------------------------------------------------------#
#------------------------Better Man Pager---------------------#
alias man='pinfo'                    #use pinfo to view man pages
alias info='pinfo'				# GNU info act like man command
#---------------------------Vim Alais's-----------------------#
alias svim='sudo vim'
alias edit='vim'                     #Who does not like typing edit <filename>?
alias sedit='sudo vim'               
#-------------------------------------------------------------#-
#---------------------------other-----------------------------#
alias open='/usr/local/bin/rifle'
alias clock='tty-clock -c -C 2 -t'                            #Feel screen clock needs tty-clock
alias mail='mutt'                                             #use mutt to check Email
alias scld='calcurse'                                         #use calcurse for schld
alias inxi='inxi -Fxzc2'                                      #See System info
alias weechat='weechat-curses'                                #not cool with out curses
alias news='newsbeuter'                                       #Beat the news
alias cal='cal -3'					                          # show 3 months
alias free='free -h'					                      # human readable
alias nano='nano -c -$'					                      # word wrapping
alias menu='pdmenu'                                           # menu makes more since the pdmenu 
alias hale9000='ruby ~/betty/main.rb'                         # i renamed betty Hale9000 
alias trash='trash-put -v'                                    # safer the rm needs trash-cli to work
alias garbage-empty='gvfs-trash --empty'					  # empty trash globally (all partitions)
alias less='less -R --tabs=4'       						  # colorful 'less', tab stops = 4
alias pmix=" pa-mixer-mk2.py"                                 # little volume cotrol dudad
alias neofetch='neofetch --backend w3m --source ~/hacker.jpg' #fetch with my pictur
alias wtf='dmesg'                                             #Really WTF MAN
alias xev-keycode="xev | grep 'keycode\|button'"
#--------------------------find Command-----------------------#
#-------------------------------------------------------------#
alias fd='find . -type d -name'
alias ff='find . -type f -name'
#-------------------------------------------------------------#
#-----------------------startx--------------------------------#
alias xx='startx ~/.xinitrc-xmonad'
alias xh='startx ~/.xinitrc-herbstluftwm'
alias xi='startx ~/.xinitrc-i3'
alias xa='startx ~/.xinitrc-awesome'
#-------------------------------------------------------------#
#----------------controll audio levels------------------------#
alias mute="pamixer -m"
alias vd="pamixer -d 10"
alias p="mocp -G &> /dev/null"
alias next="mocp -f &> /dev/null"
alias prev="mocp -r &> /dev/null"
alias vu="pamixer -i 10"
#-------------------------------------------------------------#
#-----------------------Tmux Commands-------------------------#
alias kl='tmux kill-window'
alias nw='tmux new-window'
#-------------------------------------------------------------#
#-------------------------net commands------------------------#
alias ports='netstat -nape --inet'
alias opennet='lsof -i'
alias ping='ping -c 4'
#-------------------------------------------------------------#
#-----------------------Disk Commands-------------------------#
alias localrepo='sudo sh ~/scripts/mount_IS0_repo mount'
alias df='df -hT --total'			# human readable, print filetype, and total
alias du='ncdu'					# max depth, human readable
alias fdisk="sudo fdisk -l"
#-------------------------------------------------------------#
#---------------------alias to fix dyslixia-------------------#
alias root='sudo'
alias s='sudo'
alias sodu='sudo'
#-------------------------------------------------------------#
#--------------------Power Bottun Commands--------------------#
alias halt='sudo systemctl halt'
alias reboot='sudo systemctl reboot'
alias poweroff='sudo systemctl poweroff'
#-------------------------------------------------------------#
#---------------------Systemd Commands------------------------#
alias sctl='systemctl'
alias jctl='journalctl'
alias jctlc='sudo journalctl --vacuum-size=20000'
alias jctlb='journalctl -b'
alias jctlf='journalctl -f'
alias jctlerr='journalctl -b -p3 g -v transmission'
#--------------------------wifi-------------------------------#
alias wifi='wicd-curses'                                      #Who needs Nm-applet not this guy
alias wifi_on="nmcli nm wifi on"
alias wifi_off="nmcli nm wifi off"
#-------------------------Elevated Access---------------------#
alias svim='sudo vim'
alias smount='sodu mount'
alias smake='sudo make' 
#}}}
#------------Just for fun alaises{{{
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'

alias 99bottles='x="bottles of beer";y="on the wall";for b in {99..1};do echo "$b $x $y, $b $x. Take one down pass it around, $(($b-1)) $x $y"; sleep 3;done'

alias matrix='echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r   "; else v+="\e[2m $r   "; fi; else v+="     "; fi; done; echo -e "$v"; v=""; done'

alias matrix2='echo -e "\e[31m"; while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2 $v";done;echo -e $v2;v2="";done;'

alias matrix3='COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done'

alias matrix4='echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done'

alias matrix5='tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=lcase,unblock | GREP_COLOR="1;32" grep --color "[^ ]"'

alias colorrainbow='yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done'

alias roulette='[ $[ $RANDOM % 6 ] == 0 ] && echo Die || echo Live'           # command line Russian roulette

alias einsteiny='A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein";'                 # numbers guessing game

alias etchasketch='c=12322123;x=20;y=20;while read -sn1 p;do k=${c:(p-1)*2:2};let x+=$((k/10-2));let y+=$((k%10-2));echo -en \\033[$y\;"$x"HX;done'   # use the 1 2 3 and 4 keys to move the cursor around the screen (It's an etch-a-sketch for your terminal!)
alias starwars="telnet towel.blinkenlights.nl"
#-------------------------------------------------------------#
#}}}
#----Single line functions{{{-
mkdircd() { mkdir -p -v $1; cd $1 ;}	          # create folder then cd into it
nohup-command() { nohup "$@" >/dev/null 2>&1& }   # background a process w/o error msg
w3mimg() { w3m -o imgdisplay=/usr/lib/w3m/w3mimgdisplay $1 ;}
gopen() { riffle "$@" > /dev/null 2>&1 ;}         # open in gui program 
file-permission() { stat --format '%a %n' "$@" ;}
# display mime of file application/zip, application/x-tar
file-type() { file --mime-type -b "$@" ;}
# call vim help page from shell prompt
function :h { vim +":h $1" +'wincmd o' +'nnoremap q :q!<CR>' ;}
#----archive from given directory--#
mktar() { tar cvf  "${1%%/}.tar"     "${1%%/}/"; }
mktgz() { tar cvzf "${1%%/}.tar.gz"  "${1%%/}/"; }
mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }
#----------------------------------#
#-----------spelling--------------#
check-word() { echo "$1" | aspell -a ;}
check-list() { cat "$1" | aspell list ;}
check-file() { aspell check "$1" ;}
#---------------------------------#
#--------Backing Up Files---------#
cpbak() { cp $1{,.bak} ;}		          # create backup copy
#---------------------------------#
killall-zombies() { kill -HUP $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }') ;}
#-----------------------------------#
# quickly cd out of directories using numbers, example: up 2
up() { local x='';for i in $(seq ${1:-1});do x="$x../"; done;cd $x; }

#-------------------------screen shooter called pix-----------#
export PATH_SCREENSHOT=~/Pictures/screenshots
pix() { scrot -d 2 "$PATH_SCREENSHOT/fullscr_`date +'%F_%Hh%Ms%S'`.png" ;}
#-------------------------------------------------------------#
#-----CD/DVD/floppy copy commands-------------------------------------------#
alias makeiso='pv /dev/sr0 | dd of=cd.iso'						# to backup a cd from a cdrom drive to an ISO
alias cdcopy='pv /dev/cdrom | dd of=cd.iso'						# to backup a cd from a cdrom drive to an ISO
alias diskcopy='pv /dev/dvd | dd of=disk.iso'						# to backup the disc (cd/dvd/whatever) to an ISO
alias floppycopy='pv /dev/fd0 | dd of=floppy.image'					# to duplicate a floppy disk to hard drive image file
alias partitioncopy='sudo pv /dev/sda1 | dd of=/dev/sda2 bs=4096 conv=notrunc,noerror'	# to duplicate one hard disk partition to another
#--------------------------------------------------------------------------#
#}}}
#-----------Super Power ls{{{
#----------List with Grip----------#
lsg() {

		figlet -f smkeyboard List Grep
  keyword=$(echo "$@" |  sed 's/ /.*/g')
  ls -hlA --color=yes \
  | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}' \
  | grep -iE $keyword
}

#----------------------------------#

lst() {
  ls -vAFq --color=yes -got --si --time-style=long-iso "$@" \
  | sed "s/$(date +%Y-%m-%d)/\x1b[32m     TODAY\x1b[m/;s/$(date +'%Y-%m-%d' -d yesterday)/\x1b[33m YESTERDAY\x1b[m/" \
  | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}' | tac
}

lsl() {
  ls -hl --color=yes "$@" \
  | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}'
}
#}}}
#---------Functions that use Cd{{{
#__________________________________#
#
#--Use ranger to Change diractory--#
function rcd {
    tempfile='/tmp/chosendir'
    ranger --choosedir="$tempfile" "${@:-$(pwd)}"
    test -f "$tempfile" &&
    if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
        cd -- "$(cat "$tempfile")"
    fi
    rm -f -- "$tempfile"
}
[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) '
#--LIST CONTENTS WHEN ENTERING-----#
cd() 
{
  if [ -n "$1" ]; then
    builtin cd "$@" && ls
  else
    builtin cd ~ && ls
  fi
}
#----------------------------------#
#}}}
#----------------other Functions{{{
#------------Up Info_______________#
upinfo ()
{
echo -ne "${green}uptime is ${green} \t ";uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}'
}
#----------------------------------#
#
#-------Remove white spaces------#
detox() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    filter_name=$(echo "$arg" | sed 's/%20/ /g' | sed 's/ /_/g' | tr '[:upper:]' '[:lower:]')
    mv -- "$arg" "$filter_name"
  done
}
#---------------------------------#
#
#------------Calculator-----------#
calc() {
		figlet -f larry3d Calculator 
		echo press ctrl+D to exit
  if which python2 &>/dev/null; then
    python2 -ic "from __future__ import division; from math import *; from random import *"
  elif which python3 &>/dev/null; then
    python3 -ic "from math import *; import cmath"
  elif which bc &>/dev/null; then
    bc -q -l
  else
    echo "Requires python2, python3 or bc for calculator features"
  fi
}
#---------------------------------#
#
#-----------misc------------------#
#----------Net info----------------#
netinfo() {
		
  figlet  Network Information 
  echo "router ip:" $(netstat -rn | awk 'FNR == 3 {print $2}')
  # newer system like archlinux
  ip addr | awk '/global/ {print $1,$2}' | cut -d\/ -f1
  ip addr | awk '/global/ {print $3,$4}'
  ip addr | awk '/ether/ {print $1,$2}'
  ip addr | awk '/scope link/ {print $1,$2}' | cut -d\/ -f1
  # older system like debian
  ifconfig | awk '/inet addr/ {print $1,$2}' | awk -F: '{print $1,$2}'
  ifconfig | awk '/Bcast/ {print $3}' | awk -F: '{print $1,$2}'
  ifconfig | awk '/inet addr/ {print $4}' | awk -F: '{print $1,$2}'
  ifconfig | awk '/HWaddr/ {print $4,$5}'
  ifconfig | awk '/Scope:Link/ {print $1,$3}' | cut -d\/ -f1
  # echo External IP $(curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+")
  # echo External IP: $(curl -s http://ipaddr.io/)
  # echo External IP: $(curl -s https://icanhazip.com/)
  # echo External IP: $(curl -s https://ifconfig.co/)
  # echo External IP: $(curl -s http://pasteip.me/api/cli/ && echo)
  echo external ip: $(curl -s http://ipecho.net/plain)
  echo "---------------------------------------------------"
}
#----------------------------------#
#}}}
#---------Storage controll funtions{{{
#----------mount iso's-------------#
mount-img() {
  if [ $# -lt 1 ]; then
    echo -e "mount image to access files"
    echo -e "\nUsage: $0 <img_file>"
    echo -e "\nExample: $0 foo.img"
    return 1
  fi

  mkdir -p "/tmp/$1"
  sudo mount "$PWD/$1" "/tmp/$1"

  # if mount was sucessful then cd and ls the mountpoint
  if [ $? -eq 0 ]; then
    cd "/tmp/$1" && ls
  else
    return 1
  fi
}

unmount-img() {
  if [ $# -lt 1 ]; then
    echo -e "unmount image"
    echo -e "\nUsage: $0 <img_file>"
    echo -e "\nExample: $0 foo.img"
    return 1
  fi

  sudo umount "/tmp/$1"
  rmdir "/tmp/$1"
}
#--------------------------------#
#}}}
#-------- Image Resizer (32|96|128|480|600|768|720|960|1080) {{{
#------------------------------------------------------
# Resizing Pictures to different resolutions

image-resize-32x32() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 32x32 "${arg%.*}"_32x32_resized."${arg##*.}"
  done
}

image-resize-96x96() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 96x96 "${arg%.*}"_96x96_resized."${arg##*.}"
  done
}

image-resize-128x128() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 128x128 "${arg%.*}"_128x128_resized."${arg##*.}"
  done
}

image-resize-640x480() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 640x480 "${arg%.*}"_640x480_resized."${arg##*.}"
  done
}

image-resize-800x600() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 800x600 "${arg%.*}"_800x600_resized."${arg##*.}"
  done
}

image-resize-1024x768() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 1024x768 "${arg%.*}"_1024x768_resized."${arg##*.}"
  done
}

image-resize-1280x720() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 1280x720 "${arg%.*}"_1280x720_resized."${arg##*.}"
  done
}

image-resize-1280x960() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 1280x960 "${arg%.*}"_1280x960_resized."${arg##*.}"
  done
}

image-resize-1920x1080() {
  if [ $# -lt 1 ]
  then
    echo -e "resize pictures to another resolution"
    echo -e "\nUsage:\n$0 <picture>"
    echo -e "\nExample:\n$0 pic1.png pic2.png pic3.png"
    echo -e "$0 *.jpg"
    return 1
  fi
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    convert "$arg" -resize 1920x1080 "${arg%.*}"_1920x1080_resized."${arg##*.}"
  done
}

# }}}
#-------- Format USB Stick/HDD/SDCards {{{
#------------------------------------------------------
# DEMO: https://www.youtube.com/watch?v=7txO1cdNJsQ
# DESC: format USB Stick/Hard Drive; It will create a single partition that fills the whole drive space

format2usb-ext2() {
  if [ $# -lt 2 ]; then
    echo -e "format and create a partition that fills up the whole device"
    echo -e "\nUsage: $0 <label> <device>"
    echo -e "Example: $0 MY_USB sdx"
    return 1
  fi

  # check if the device is mounted
  mount_status=$(mount | grep /dev/"$2" | wc -l)
  if [ "$mount_status" -ne 0 ]
  then
    lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep "$2"
    echo -e "${Red}/dev/$2 is mounted. You have to unmount /dev/$2 ${Color_Off}"
    return 1
  fi

  # list out all drives
  lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep --color -E "$2|$"
  
  echo -n -e "${Red}WARNING: You are about to FORMAT a drive. Do you want to continue? [y/n] ${Color_Off}"
  read REPLY
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "... You chose to continue"
  else
    return 1
  fi

  # delete existing partition then create new linux partition
  echo -e "d\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\no\nn\np\n1\n\n\nw" | sudo fdisk /dev/"$2"

  # delete partiton x8 using d\n\n
  # d    delete a partition
  #      default, partition

  # o    create a new empty DOS partition table
  # n    add a new partition
  # p    print the partition table
  # 1    partition number 1
  #      default, start immediately after preceding partition
  #      default, extend partition to end of disk
  # w    write table to disk and exit

  # format device
  echo -e "y\n" | sudo mkfs.ext2 -L "$1" /dev/"$2"1

  # set permission
  mkdir -p /tmp/testmount
  sudo mount /dev/"$2"1 /tmp/testmount
  sudo chmod -R 777 /tmp/testmount
  sudo umount /tmp/testmount
  rmdir /tmp/testmount
}

format2usb-ext3() {
  if [ $# -lt 2 ]; then
    echo -e "format and create a partition that fills up the whole device"
    echo -e "\nUsage: $0 <label> <device>"
    echo -e "Example: $0 MY_USB sdx"
    return 1
  fi

  # check if the device is mounted
  mount_status=$(mount | grep /dev/"$2" | wc -l)
  if [ "$mount_status" -ne 0 ]
  then
    lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep "$2"
    echo -e "${Red}/dev/$2 is mounted. You have to unmount /dev/$2 ${Color_Off}"
    return 1
  fi

  # list out all drives
  lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep --color -E "$2|$"

  echo -n -e "${Red}WARNING: You are about to FORMAT a drive. Do you want to continue? [y/n] ${Color_Off}"
  read REPLY
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "... You chose to continue"
  else
    return 1
  fi

  # delete existing partition then create new linux partition
  echo -e "d\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\no\nn\np\n1\n\n\nw" | sudo fdisk /dev/"$2"

  # delete partiton x8 using d\n\n
  # d    delete a partition
  #      default, partition

  # o    create a new empty DOS partition table
  # n    add a new partition
  # p    print the partition table
  # 1    partition number 1
  #      default, start immediately after preceding partition
  #      default, extend partition to end of disk
  # w    write table to disk and exit

  # format device
  echo -e "y\n" | sudo mkfs.ext3 -L "$1" /dev/"$2"1

  # set permission
  mkdir -p /tmp/testmount
  sudo mount /dev/"$2"1 /tmp/testmount
  sudo chmod -R 777 /tmp/testmount
  sudo umount /tmp/testmount
  rmdir /tmp/testmount
}

format2usb-ext4() {
  if [ $# -lt 2 ]; then
    echo -e "format and create a partition that fills up the whole device"
    echo -e "\nUsage: $0 <label> <device>"
    echo -e "Example: $0 MY_USB sdx"
    return 1
  fi

  # check if the device is mounted
  mount_status=$(mount | grep /dev/"$2" | wc -l)
  if [ "$mount_status" -ne 0 ]
  then
    lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep "$2"
    echo -e "${Red}/dev/$2 is mounted. You have to unmount /dev/$2 ${Color_Off}"
    return 1
  fi

  # list out all drives
  lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep --color -E "$2|$"

  echo -n -e "${Red}WARNING: You are about to FORMAT a drive. Do you want to continue? [y/n] ${Color_Off}"
  read REPLY
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "... You chose to continue"
  else
    return 1
  fi

  # delete existing partition then create new linux partition
  echo -e "d\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\no\nn\np\n1\n\n\nw" | sudo fdisk /dev/"$2"

  # delete partiton x8 using d\n\n
  # d    delete a partition
  #      default, partition

  # o    create a new empty DOS partition table
  # n    add a new partition
  # p    print the partition table
  # 1    partition number 1
  #      default, start immediately after preceding partition
  #      default, extend partition to end of disk
  # w    write table to disk and exit

  # format device
  echo -e "y\n" | sudo mkfs.ext4 -L "$1" /dev/"$2"1

  # set permission
  mkdir -p /tmp/testmount
  sudo mount /dev/"$2"1 /tmp/testmount
  sudo chmod -R 777 /tmp/testmount
  sudo umount /tmp/testmount
  rmdir /tmp/testmount
}

format2usb-fat32() {
  if [ $# -lt 2 ]; then
    echo -e "format and create a partition that fills up the whole device"
    echo -e "\nUsage: $0 <label> <device>"
    echo -e "Example: $0 MY_USB sdx"
    return 1
  fi

  # check if the device is mounted
  mount_status=$(mount | grep /dev/"$2" | wc -l)
  if [ "$mount_status" -ne 0 ]
  then
    lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep "$2"
    echo -e "${Red}/dev/$2 is mounted. You have to unmount /dev/$2 ${Color_Off}"
    return 1
  fi

  # list out all drives
  lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep --color -E "$2|$"

  echo -n -e "${Red}WARNING: You are about to FORMAT a drive. Do you want to continue? [y/n] ${Color_Off}"
  read REPLY
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "... You chose to continue"
  else
    return 1
  fi

  # delete existing partition then create new linux partition
  echo -e "d\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\no\nn\np\n1\n\n\nt\nb\nw" | sudo fdisk /dev/"$2"

  # delete partiton x8 using d\n\n
  # d    delete a partition
  #      default, partition

  # o    create a new empty DOS partition table
  # n    add a new partition
  # p    print the partition table
  # 1    partition number 1
  #      default, start immediately after preceding partition
  #      default, extend partition to end of disk
  # t    change a partition type (L to list all types)
  # b    W95 FAT32
  # w    write table to disk and exit

  # fat32 likes the labels to be in uppercase
  label_name=$(echo "$1" | tr '[:lower:]' '[:upper:]')

  # format device
  sudo mkfs.fat -F 32 -n "$label_name" -I /dev/"$2"1

  # set permission
  mkdir -p /tmp/testmount
  sudo mount /dev/"$2"1 /tmp/testmount
  sudo chmod -R 777 /tmp/testmount
  sudo umount /tmp/testmount
  rmdir /tmp/testmount
}

format2usb-ntfs() {
  if [ $# -lt 2 ]; then
    echo -e "format and create a partition that fills up the whole device"
    echo -e "\nUsage: $0 <label> <device>"
    echo -e "Example: $0 MY_USB sdx"
    return 1
  fi

  # check if the device is mounted
  mount_status=$(mount | grep /dev/"$2" | wc -l)
  if [ "$mount_status" -ne 0 ]
  then
    lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep "$2"
    echo -e "${Red}/dev/$2 is mounted. You have to unmount /dev/$2 ${Color_Off}"
    return 1
  fi

  # list out all drives
  lsblk -o "NAME,SIZE,FSTYPE,TYPE,LABEL,MOUNTPOINT,UUID" | grep --color -E "$2|$"

  echo -n -e "${Red}WARNING: You are about to FORMAT a drive. Do you want to continue? [y/n] ${Color_Off}"
  read REPLY
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "... You chose to continue"
  else
    return 1
  fi

  # delete existing partition then create new linux partition
  echo -e "d\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\nd\n\no\nn\np\n1\n\n\nt\n7\nw" | sudo fdisk /dev/"$2"

  # delete partiton x8 using d\n\n
  # d    delete a partition
  #      default, partition

  # o    create a new empty DOS partition table
  # n    add a new partition
  # p    print the partition table
  # 1    partition number 1
  #      default, start immediately after preceding partition
  #      default, extend partition to end of disk
  # t    change a partition type (L to list all types)
  # 7    HPFS/NTFS/exFAT
  # w    write table to disk and exit

  # format device
  sudo mkfs.ntfs -f -L "$1" /dev/"$2"1

  # set permission
  mkdir -p /tmp/testmount
  sudo mount /dev/"$2"1 /tmp/testmount
  sudo chmod -R 777 /tmp/testmount
  sudo umount /tmp/testmount
  rmdir /tmp/testmount
}

# }}}
#---------Recordmydesktop CLI {{{
#------------------------------------------------------
# http://www.pclinuxos.com/forum/index.php/topic,97181.msg822796.html#msg822796
# Screen capture software
# Ctrl+C	Stop
# Ctrl+C x2	Cancle rendering
# BUG: RMD Adjusted recording window, which cuts 10 pixel from the height, thus we have to use offset -x -y
# https://wiki.archlinux.org/index.php/RecordMyDesktop
# http://sourceforge.net/p/recordmydesktop/discussion/590957/thread/cf788e96/
# https://groups.google.com/forum/#!topic/linux.debian.bugs.dist/reE8_9fqqAw
# native reso 1680x1050 -- > rmd reso 1080x1040, offset y axis -y 6
# SOUND LAG? lower the freq; 45000, 44100, 22050
# http://www.kkoncepts.net/blog/fixing-out-sync-audio-and-video-ffmpeg
RMD_OUTPUT=~/Public/screencast/rr_movie_baking.ogv

# Frequency; lower to fix sound lag; 45000, 44100, 22050
RMD_FREQ=22050

# Frames per second
RMD_FPS=30

# Channel (mono = 1 ; dual = 2)
RMD_CHANNELS=1

# SoundCard (pulse for pulseaudio; install pavucontrol to change pulse settings)
#            hw:0,1 for directly communicating with your soundcard
#            to get a list of sound device:
#            	arecord -l
#            	aplay -l
#            	cat /proc/asound/pcm
#            	alsamixer and hit F6
# FF_SOUNDCARD=pulse
# FF_SOUNDCARD=hw:0,1
RMD_SOUNDCARD=hw:3,0

rmd-all() { recordmydesktop --no-wm-check --no-frame --full-shots --fps $RMD_FPS --channels $RMD_CHANNELS --device $RMD_SOUNDCARD --freq $RMD_FREQ --overwrite -o $RMD_OUTPUT ;}

# Benq Monitor; 1680x1050 (make sure 2nd monitor is higher res)
# Initial recording window is set to:
# X:0   Y:0    Width:1680    Height:1050
# Adjusted recording window is set to:
# X:0   Y:0    Width:1680    Height:1056
rmd-benq() { recordmydesktop --no-wm-check --no-frame --full-shots --width 1680 --height 1050 --fps $RMD_FPS --channels $RMD_CHANNELS --device $RMD_SOUNDCARD --freq $RMD_FREQ --overwrite -o $RMD_OUTPUT ;}


# ProscanTV; 1920x1080 --> 1920x1072 ; X offset by 1680
# Initial recording window is set to:
# X:0   Y:0    Width:1920    Height:1080
# Adjusted recording window is set to:
# X:0   Y:4    Width:1920    Height:1072
rmd-proscantv() { recordmydesktop --no-wm-check --no-frame --full-shots -x 1680 --width 1920 --height 1072 --fps $RMD_FPS --channels $RMD_CHAN --device $RMD_DEV --freq $RMD_FREQ --overwrite -o $RMD_OUTPUT ;}

# Examples
# select window
# E1: (select window); recordmydesktop --no-frame --full-shots --fps 30 --channels 2 --freq 44100 --windowid $(xwininfo | awk '/Window id:/ {print $4}') --overwrite -o out.ogv ;}
# E2: recordmydesktop --no-wm-check --no-frame --width 1680 --height 1050 --fps 30 --channels 1 --device hw:3,0 --freq 44100 --overwrite -o out.ogv ;}
#E3: (fullscreen); recordmydesktop --no-frame --full-shots --fps 30 --channels 2 --freq 44100 --overwrite -o out.ogv ;}

#}}}
#----------Rip Dvd's from Command line{{{
export VIDEOS='$HOME/Videos'
 
#-----------------------------------------------------------------------#
#tuction to use handbrake to rip Dvd's
#USE= rip <name of movie>
 function rip() {
 handbrakeCLI -i /dev/sr0 -o ${videos}/${1}.mp4 -L -U -F -f mp4 -e x264 -b 4000 -B 192
 }

#-----------------------------------------------------------------------#
#  Convert raw/bin/cue/ccd/img/mdf/nrg to iso
function disc2iso () {
    if [[ $# == 0 || $1 == "--help" || $1 == "-h" ]]; then
      echo -e "Converts raw|bin|cue|ccd|img|mdf|nrg disc image to ISO"
      echo -e "Usage: $0 <disc_image>"
    fi
    for i in $*; do
      if [[ ! -f "$i" ]]; then
        echo "'$i' is not a valid file; jumping it"
      else
        echo -n "converting $i..."
        # OUT=`echo $i | cut -d '.' -f 1`
        case $i in
              *.raw ) bchunk "$i" "${i%.*}.iso" ;; #raw=bin
        *.bin|*.cue ) bchunk "${i%.*}.bin" "${i%.*}.cue" "${i%.*}.iso" ;; # bin,cue
        *.ccd|*.img ) ccd2iso "${i%.*}.img" "${i%.*}.iso" ;; # Clone CD images
              *.mdf ) mdf2iso "$i" "${i%.*}.iso" ;; # Alcohol images
              *.nrg ) nrg2iso "$i" "${i%.*}.iso" ;; # Nero images
                  * ) echo "$0 don't know de extension of '$i'";;
        esac
        if [[ $? != 0 ]]; then
          echo -e "${R}ERROR!${W}"
        else
          echo -e "${G}done!${W}"
        fi
      fi
    done
}
#}}}
#-------- Archive Manager CLI {{{
#------------------------------------------------------
archive-append() { atool -a "$@" ;}
archive-extract() { atool -x "$@" ;}
archive-list() { atool -l "$1" | less -N ;}
archive-search() { atool -l "$1" | grep -i "$2" ;}

# create archive
archive-create-7z() { atool -a archive.7z "$@" ;}
archive-create-zip() { atool -a archive.zip "$@" ;}
archive-create-rar() { atool -a archive.rar "$@" ;}
archive-create-tar() { atool -a archive.tar "$@" ;}
archive-create-targz() { atool -a archive.tar.gz "$@" ;}
archive-create-cbz() { atool -a archive.zip "$@" && mv -- archive.zip archive.cbz ;}
archive-create-cbr() { atool -a archive.rar "$@" && mv -- archive.rar archive.cbr ;}

# converting archive
convert2archive-tar() { arepack -F .tar -e "$@" ;}
convert2archive-zip() { arepack -F .zip -e "$@" ;}
convert2archive-rar() { arepack -F .rar -e "$@" ;}
convert2archive-targz() { arepack -F .tar.gz -e "$@" ;}
convert2archive-7z() { arepack -F .7z -e "$@" ;}
convert2archive-cbz() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    if [[ ! -f "${arg%%.*}".zip && ! -f "${arg%%.*}".cbz ]]; then
      arepack -F .zip -e "$arg" && mv -- "${arg%%.*}".zip "${arg%%.*}".cbz
    else
      if [[ -f "${arg%%.*}".zip && ! -f "${arg%%.*}".cbz ]]; then
        mv -v -- "${arg%%.*}".zip "${arg%%.*}".cbz
      fi
    fi
  done
}
convert2archive-cbr() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    if [[ ! -f "${arg%%.*}".rar && ! -f "${arg%%.*}".cbr ]]; then
      arepack -F .rar -e "$arg" && mv -- "${arg%%.*}".rar "${arg%%.*}".cbr
    else
      if [[ -f "${arg%%.*}".rar && ! -f "${arg%%.*}".cbr ]]; then
        mv -v -- "${arg%%.*}".rar "${arg%%.*}".cbr
      fi
    fi
  done
}

#}}}
#-------- Sound Effects {{{
#------------------------------------------------------
# http://whatnotlinux.blogspot.com/2011/12/enterprise-ambiance.html
ambiance-whitenoise() { play -n -c1 synth whitenoise band -n 100 20 band -n 50 20 gain +25  fade h 1 864000 1 ;}
ambiance-whitenoisewider() { play -n -c2 synth whitenoise band -n 100 24 band -n 300 100 gain +20 ;}
ambiance-pinknoise() { play -c2 -n synth pinknoise band -n 280 80 band -n 60 25 gain +20 treble +40 500 bass -3 20 flanger 4 2 95 50 .3 sine 50 lin ;}

#}}}
#-------- Music Tagging CLI {{{
#------------------------------------------------------
tag-encoding-v2.3() { eyeD3 --encoding=utf8 --to-v2.3 "$@" ;}
tag-encoding-v2.4() { eyeD3 --encoding=utf8 --to-v2.4 "$@" ;}
tag-show() { eyeD3 "$@" ;}
tag-album() { eyeD3 -A "$1" "${@:2}" ;}
tag-albumartist() { eyeD3 -b "$1" "${@:2}" ;}
tag-artist() { eyeD3 -a "$1" "${@:2}" ;}
tag-title() { eyeD3 -t "$1" "${@:2}" ;}
tag-number() { eyeD3 -n "$1" "${@:2}" ;}
tag-genre() { eyeD3 -G "$1" "${@:2}" ;}
tag-listgenre() { eyeD3 --plugin=genres ;}
tag-year() { eyeD3 -Y "$1" "${@:2}" ;}
tag-comment() { eyeD3 -c "$1" "${@:2}" ;}
tag-image-remove() { eyeD3 --remove-all-images "$@" ;}
tag-image-add() { eyeD3 --add-image "$1":FRONT_COVER "${@:2}" ;}
tag-image-extract() { eyeD3 --write-images=. "$@" ;}

# use existing music tags to rename filename
tag-to-filename-num-title() { eyeD3 --rename '$track:num - $title' "$@" ;}
tag-to-filename-artist-album-num-title() { eyeD3 --rename '$artist - $album - $track:num - $title' "$@" ;}
tag-to-filename-artist-title() { eyeD3 --rename '$artist - $title' "$@" ;}
tag-to-filename-artist-album-title() { eyeD3 --rename '$artist - $album - $title' "$@" ;}


# use existing filename to fill in music tags
# 05 Desperado.mp3 --> fill in track/title
tag-filltag-from-filename-num-space-title() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    tracknum=$(echo "${arg%.*}" | cut -d ' ' -f1 | awk '{$1=$1};1' )
    titlename=$(echo "${arg%.*}" | cut -d ' ' -f2- | awk '{$1=$1};1' )
    eyeD3 --track "$tracknum" --title "$titlename" "$arg"
  done
}

# 05 - Desperado.mp3 --> fill in track/title
tag-filltag-from-filename-num-dash-title() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    tracknum=$(echo "${arg%.*}" | awk -F' - ' '{print $1}' | awk '{$1=$1};1' )
    titlename=$(echo "${arg%.*}" | awk -F' - ' '{print $2}' | awk '{$1=$1};1' )
    eyeD3 --track "$tracknum" --title "$titlename" "$arg"
  done
}

# Rihanna - Desperado.mp3 --> fill in artist/albumartist/title
tag-filltag-from-filename-artist-dash-title() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    artistname=$(echo "${arg%.*}" | awk -F' - ' '{print $1}' | awk '{$1=$1};1' )
    titlename=$(echo "${arg%.*}" | awk -F' - ' '{print $2}' | awk '{$1=$1};1' )
    eyeD3 --artist "$artistname" --title "$titlename" "$arg"
  done
}

# Desperado.mp3 --> fill in title
tag-filltag-from-filename-titleonly() {
  myArray=( "$@" )
  for arg in "${myArray[@]}"; do
    eyeD3 --title "${arg%.*}" "$arg"
  done
}

# }}}
#-------- Convert to Image {{{
#------------------------------------------------------
# pdftoppm convert pdf to images
# http://askubuntu.com/a/50180
convert_pdf_to_png() {
    if [ $# -lt 1 ]
    then
        echo -e "convert PDF document to PNG image (default dpi is 150)"
        echo -e "\nUsage:\n$0 <pdf> <dpi> <startingpage> <endingpage>"
        echo -e "\nall pages to images:\n$0 file.pdf"
        echo -e "\nchange dpi (common dpi are 150, 300, 600):\n$0 file.pdf 300"
        echo -e "\nsingle page to image:\n$0 file.pdf 300 5"
        echo -e "\nmultiple pages to images:\n$0 file.pdf 300 5 12"

        return 1
    fi
    pdftoppm -png "$1" "${1%.*}"-"${2:-150}"DPI -r "${2:-150}" -f "$3" -l "${4:-$3}"
}

convert_pdf_to_jpg() {
    if [ $# -lt 1 ]
    then
        echo -e "convert PDF document to JPEG image (default dpi is 150)"
        echo -e "\nUsage:\n$0 <pdf> <dpi> <startingpage> <endingpage>"
        echo -e "\nall pages to images:\n$0 file.pdf"
        echo -e "\nchange dpi (common dpi are 150, 300, 600):\n$0 file.pdf 300"
        echo -e "\nsingle page to image:\n$0 file.pdf 300 5"
        echo -e "\nmultiple pages to images:\n$0 file.pdf 300 5 12"

        return 1
    fi
    pdftoppm -jpeg "$1" "${1%.*}"-"${2:-150}"DPI -r "${2:-150}" -f "$3" -l "${4:-$3}"
}

convert_pdf_to_tiff() {
    if [ $# -lt 1 ]
    then
        echo -e "convert PDF document to TIFF image (default dpi is 150)"
        echo -e "\nUsage:\n$0 <pdf> <dpi> <startingpage> <endingpage>"
        echo -e "\nall pages to images:\n$0 file.pdf"
        echo -e "\nchange dpi (common dpi are 150, 300, 600):\n$0 file.pdf 300"
        echo -e "\nsingle page to image:\n$0 file.pdf 300 5"
        echo -e "\nmultiple pages to images:\n$0 file.pdf 300 5 12"

        return 1
    fi
    pdftoppm -tiff "$1" "${1%.*}"-"${2:-150}"DPI -r "${2:-150}" -f "$3" -l "${4:-$3}"
}

convert_pdf_to_pgm-grayscale() {
    if [ $# -lt 1 ]
    then
        echo -e "convert PDF document to PGM Grayscale image (default dpi is 150)"
        echo -e "\nUsage:\n$0 <pdf> <dpi> <startingpage> <endingpage>"
        echo -e "\nall pages to images:\n$0 file.pdf"
        echo -e "\nchange dpi (common dpi are 150, 300, 600):\n$0 file.pdf 300"
        echo -e "\nsingle page to image:\n$0 file.pdf 300 5"
        echo -e "\nmultiple pages to images:\n$0 file.pdf 300 5 12"

        return 1
    fi
    pdftoppm -gray "$1" "${1%.*}"-"${2:-150}"DPI -r "${2:-150}" -f "$3" -l "${4:-$3}"
}

convert_pdf_to_pbm-monochrome() {
    if [ $# -lt 1 ]
    then
        echo -e "convert PDF document to PBM Monochrome image (default dpi is 150)"
        echo -e "\nUsage:\n$0 <pdf> <dpi> <startingpage> <endingpage>"
        echo -e "\nall pages to images:\n$0 file.pdf"
        echo -e "\nchange dpi (common dpi are 150, 300, 600):\n$0 file.pdf 300"
        echo -e "\nsingle page to image:\n$0 file.pdf 300 5"
        echo -e "\nmultiple pages to images:\n$0 file.pdf 300 5 12"

        return 1
    fi
    pdftoppm -mono "$1" "${1%.*}"-"${2:-150}"DPI -r "${2:-150}" -f "$3" -l "${4:-$3}"
}
#}}}
