# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# 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\[\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 -F'

	alias  grep=' grep --color=auto'
	alias fgrep='fgrep --color=auto'
	alias egrep='egrep --color=auto'
fi

# 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
# ~/.aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.aliases ]; then
	. ~/.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

#==============================================================================#

#******************************************************************************#
#	Color chart
#------------------------------------------------------------------------------#
txtblk="\[\e[0;30m\]" # Black - Regular
txtred="\[\e[0;31m\]" # Red
txtgrn="\[\e[0;32m\]" # Green
txtylw="\[\e[0;33m\]" # Yellow
txtblu="\[\e[0;34m\]" # Blue
txtpur="\[\e[0;35m\]" # Purple
txtcyn="\[\e[0;36m\]" # Cyan
txtwht="\[\e[0;37m\]" # White
txtgry="\[\e[0;90m\]" # Gray
dimblk="\[\e[2;30m\]" # Black - Dim
dimred="\[\e[2;31m\]" # Red
dimgrn="\[\e[2;32m\]" # Green
dimwht="\[\e[2;37m\]" # White
bldblk="\[\e[1;30m\]" # Black - Bold
bldred="\[\e[1;31m\]" # Red
bldgrn="\[\e[1;32m\]" # Green
bldylw="\[\e[1;33m\]" # Yellow
bldblu="\[\e[1;34m\]" # Blue
bldpur="\[\e[1;35m\]" # Purple
bldcyn="\[\e[1;36m\]" # Cyan
bldwht="\[\e[1;37m\]" # White
unkblk="\[\e[4;30m\]" # Black - Underline
undred="\[\e[4;31m\]" # Red
undgrn="\[\e[4;32m\]" # Green
undylw="\[\e[4;33m\]" # Yellow
undblu="\[\e[4;34m\]" # Blue
undpur="\[\e[4;35m\]" # Purple
undcyn="\[\e[4;36m\]" # Cyan
undwht="\[\e[4;37m\]" # White
bakblk="\[\e[40m\]"   # Black - Background
bakred="\[\e[41m\]"   # Red
badgrn="\[\e[42m\]"   # Green
bakylw="\[\e[43m\]"   # Yellow
bakblu="\[\e[44m\]"   # Blue
bakpur="\[\e[45m\]"   # Purple
bakcyn="\[\e[46m\]"   # Cyan
bakwht="\[\e[47m\]"   # White
txtrst="\[\e[0m\]"    # Text Reset
function colors {
	echo -e "\n\
$txtblk txtblk $txtrst \n\
$txtred txtred $txtrst \n\
$txtgrn txtgrn $txtrst \n\
$txtylw txtylw $txtrst \n\
$txtblu txtblu $txtrst \n\
$txtpur txtpur $txtrst \n\
$txtcyn txtcyn $txtrst \n\
$txtwht txtwht $txtrst \n\
$bldblk bldblk $txtrst \n\
$bldred bldred $txtrst \n\
$bldgrn bldgrn $txtrst \n\
$bldylw bldylw $txtrst \n\
$bldblu bldblu $txtrst \n\
$bldpur bldpur $txtrst \n\
$bldcyn bldcyn $txtrst \n\
$bldwht bldwht $txtrst \n\
$unkblk unkblk $txtrst \n\
$undred undred $txtrst \n\
$undgrn undgrn $txtrst \n\
$undylw undylw $txtrst \n\
$undblu undblu $txtrst \n\
$undpur undpur $txtrst \n\
$undcyn undcyn $txtrst \n\
$undwht undwht $txtrst \n\
$bakblk bakblk $txtrst \n\
$bakred bakred $txtrst \n\
$badgrn badgrn $txtrst \n\
$bakylw bakylw $txtrst \n\
$bakblu bakblu $txtrst \n\
$bakpur bakpur $txtrst \n\
$bakcyn bakcyn $txtrst \n\
$bakwht bakwht $txtrst \n"
}
#******************************************************************************#


#******************************************************************************#
#	PS1
#------------------------------------------------------------------------------#
if [ `id -u` ==  0 ]; then
	PS1='\u@\h:\w\$ '"$txtrst"
	export PROMPT_COMMAND='if (($? > 0)); then echo -ne "\e[1;31m"; else echo -ne "\e[1;36m"; fi;';
else
	PS1='[\u@\h \W]\$ '"$txtrst"
	export PROMPT_COMMAND='export ret=$?; if (($ret > 0)); then echo -ne "\e[1;31m"; else echo -ne "\e[1;32m"; fi;';
fi
default_PS1="$PS1"
#******************************************************************************#


#******************************************************************************#
#	Autocomplete commands
#------------------------------------------------------------------------------#
complete -W "$(echo `cat ~/.bash_history | egrep '^ssh '  | sort | uniq | sed 's/^ssh //'`;)"  ssh
complete -W "$(echo `cat ~/.bash_history | egrep '^ping ' | sort | uniq | sed 's/^ping //'`;)" ping
#******************************************************************************#


#******************************************************************************#
#	Confirm?
#------------------------------------------------------------------------------#
confirm () {
    # call with a prompt string or use a default
    read -r -p "${1:-Are you sure? [y/N]} " response
    case $response in
        [yY][eE][sS]|[yY])
            true
            ;;
        *)
            false
            ;;
    esac
}
#******************************************************************************#


#******************************************************************************#
#	Run!
#------------------------------------------------------------------------------#
function run() {
	nohup "$@" &>/dev/null &
}
alias run="run"
#******************************************************************************#


#******************************************************************************#
#	Each
#------------------------------------------------------------------------------#
function each()
{
	list_each=`ls $2`

	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	for i in $list_each
	do
		if [ -f $i ]
		then
			echo $1 "'"$i"'" $3
			eval $1 "'"$i"'" $3
		fi
	done

	IFS=$SAVEIFS
}
#******************************************************************************#

#******************************************************************************#
#	Surf
#------------------------------------------------------------------------------#
function surf()
{
	list_surf=`ls`

	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	echo -e "$dimgrn[surfer@"`hostname`" "`pwd`"]\$ $txtrst"
	echo $@
	eval $@

	for j in $list_surf
	do
#		if [ -f $j ]
#		then
#			echo "$1 \"$j\" $3"
#			eval "$1 \"$j\" $3"
#		fi

		if [ -d $j ]
		then
			cd "$j"
			surf "$@"
			cd ..
		fi
	done

	IFS=$SAVEIFS
}
#******************************************************************************#


#******************************************************************************#
#	Windowsify filenames!
#------------------------------------------------------------------------------#
function windowsify() {
	old_name=`echo $1 | sed s/\"/\\\\\"/g`
	new_name=`echo $i | sed 's/[\\\:*?\"<>|]//g'`
	if [[ $old_name == $new_name ]]; then echo "Does not need change."; return; fi;
	echo mv "'"$old_name"'" "'"$new_name"'"
	eval mv "'"$old_name"'" "'"$new_name"'" 2>/dev/null
}
#******************************************************************************#


#******************************************************************************#
#	Hard Link
#------------------------------------------------------------------------------#
function hardlink()
{
	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	name=`echo $1 | sed 's/\/$//' | sed 's/.*\(\/[^\/]*$\)/.\1/'`
	echo $name

	if [ -f $1 ]
	then
		echo 'file'
		ln "$1" "$name"
	fi

	if [ -d $1 ]
	then
		echo 'directory'
		mkdir "$name"
		for i in $(/bin/ls $1)
		do
			ln "$1/$i" "$name/$i"
		done
	fi

	IFS=$SAVEIFS
}
alias hardlink="hardlink"
#******************************************************************************#


#******************************************************************************#
#	x265
#------------------------------------------------------------------------------#
function x265()
{
	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	for i in $(ls $@)
	do
		i=`echo "$i" | sed 's/\"/\\\"/g'`
		#echo "$i"

		if echo "$i" | grep ".x265." &>/dev/null
		then
			echo "\"$i\" is already x265!"
			continue
		fi

		j=`echo "$i" | sed 's/\(\.[^.]*$\)/.x265\1\.mp4/' | sed 's/\.mkv\.mp4$/\.mkv/' | sed 's/\.x265.*\.mp4$/\.x265\.mp4/'`
		#echo "$j"

		command="ffmpeg -n -i \"$i\" -c:v libx265 \"$j\""
		echo $command
		eval $command
	done

	IFS=$SAVEIFS
}
alias x265="x265"
#******************************************************************************#


#******************************************************************************#
#	x264
#------------------------------------------------------------------------------#
function x264()
{
	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	for i in $(ls $@)
	do
		i=`echo "$i" | sed 's/\"/\\\"/g'`
		#echo "$i"

		j=`echo "$i" | sed 's/\(\.[^.]*$\)/.x264\1\.mp4/' | sed 's/\.mkv\.mp4$/\.mkv/' | sed 's/\.x264.*\.mp4$/\.x264\.mp4/' | sed 's/\.x265//'`
		#echo "$j"

		command="ffmpeg -n -i \"$i\" -c:v h264 \"$j\""
		echo $command
		eval $command
	done

	IFS=$SAVEIFS
}
alias x264="x264"
#******************************************************************************#


#******************************************************************************#
#	Rename picture to datetime format
#------------------------------------------------------------------------------#
function rename_to_datetime()
{
	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	for i in $(ls $@)
	do
		newname=`identify -format "%[EXIF:DateTimeOriginal]" $i | sed 's/://g' | sed 's/\ /_/' | sed 's/$/.jpg/'`
		if [ "$newname" = "" ]
		then
			newname=`identify -format "%[DATE:Modify]" $i | sed 's/://g' | sed 's/-//g' | sed 's/T/_/' | sed 's/+.*$/.jpg/'`
		fi
		command="mv -n \"$i\" \"$newname\""
		echo $command
		eval $command
	done

	IFS=$SAVEIFS
}
alias rename_to_datetime="rename_to_datetime"
#******************************************************************************#


#******************************************************************************#
#	Aliases
#------------------------------------------------------------------------------#
alias reload='source ~/.bashrc'
alias ~reset="/bin/reset"

alias ll='ls -lAhF'
alias lx='ls -lAhFX'

alias cp='cp -i'
alias  mv='/bin/mv -i'
alias ~mv="/bin/mv -i"
alias rmt='mv -t ~/.local/share/Trash/files'
alias rmp='/bin/rm'
alias ~rm="/bin/rm"
alias mkdir='mkdir -p -v'

alias ~grep="/bin/grep --color=auto"
alias ~diff="/bin/diff"

alias unmount="umount"

alias cd..="cd .."
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

alias path='echo -e ${PATH//:/\\n}'
alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'

alias du='du -khc'
alias df='df -khT'

alias wget='wget -c'

alias psg="ps -e | /bin/grep"

alias cal="cal -3"

alias which='type -a'

alias pong="ping 8.8.8.8"
alias atx="chmod a+x"

alias retor="sudo service tor restart"
alias rest4="sudo service stunnel4 stop && sudo service stunnel4 start"
alias refont="sudo fc-cache -f -v"
alias reconky="killall conky &>/dev/null; nohup conky &>/dev/null &"

alias pyserve="python -m SimpleHTTPServer"

alias betty="~/.betty/main.rb"

alias subtitlefixer="~/.local/bin/SubtitleFixer/SubtitleFixer"

alias double_png='for i in $(ls *.png); do convert -resize 200% $i re_$i; done'
alias to_512='for i in $(ls *.png); do convert -crop 512x512-128-128\! -background none -flatten $i re_$i; done'

alias gephi="~/.gephi/bin/gephi"

alias jadify="run ~/.jadify.sh"
alias yfidaj="killall .jadify.sh 2>/dev/null"
alias jadifv="~/.jadify.sh"

alias matrix='echo -e "\e[32m"; 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=""; sleep 0.05; done;'
alias screensaver='for ((;;)); do echo -ne "\033[$((1+RANDOM%LINES));$((1+RANDOM%COLUMNS))H\033[$((RANDOM%2));3$((RANDOM%8))m$((RANDOM%10))"; sleep 0.1 ; done' # terminal screensaver
#******************************************************************************#


#******************************************************************************#
#	Tailoring 'less'
#------------------------------------------------------------------------------#
alias more='less'
export PAGER=less
#export LESSCHARSET='latin1'
#export LESSOPEN='| /usr/bin/lesspipe.sh %s 2>&-'
#	# Use this if lesspipe.sh exists
#export LESS='-i -N -w  -z-4 -g -e -M -X -F -R -P%t?f%f \
#:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
#******************************************************************************#


#******************************************************************************#
#	Bash tips
#------------------------------------------------------------------------------#
function tips() {
# Copyright 2007 - 2010 Christopher Bratusek
cat <<EOF
DIRECTORIES
-----------
~-		Previous working directory
pushd tmp	Push tmp && cd tmp
popd		Pop && cd

GLOBBING AND OUTPUT SUBSTITUTION
--------------------------------
ls a[b-dx]e	Globs abe, ace, ade, axe
ls a{c,bl}e	Globs ace, able
\$(ls)		\`ls\` (but nestable!)

HISTORY MANIPULATION
--------------------
!!		Last command
!?foo		Last command containing \`foo'
^foo^bar^	Last command containing \`foo', but substitute \`bar'
!!:0		Last command word
!!:^		Last command's first argument
!\$		Last command's last argument
!!:*		Last command's arguments
!!:x-y		Arguments x to y of last command
C-s		search forwards in history
C-r		search backwards in history

LINE EDITING
------------
M-d		kill to end of word
C-w		kill to beginning of word
C-k		kill to end of line
C-u		kill to beginning of line
M-r		revert all modifications to current line
C-]		search forwards in line
M-C-]		search backwards in line
C-t		transpose characters
M-t		transpose words
M-u		uppercase word
M-l		lowercase word
M-c		capitalize word

COMPLETION
----------
M-/		complete filename
M-~		complete user name
M-@		complete host name
M-\$		complete variable name
M-!		complete command name
M-^		complete history
EOF

echo ""
echo "LS COLORS"
echo "---------"

IFSBKP=$IFS
#eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;" | sed -e 's/:/="/g; s/\;/"\n/g')
eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;ow:other writable;st:sticky;ex:executable;" | sed -e 's/:/="/g; s/\;/"\n/g')
{
	IFS=':'
	counter='1'
	for i in $LS_COLORS; do
		echo -ne "\e[${i#*=}m$(printf "%-20s\e[m" "$(x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x")")"
		if [ $(expr $counter % 4) == "0" ]; then
			echo
		fi
		counter="`expr $counter + 1`"
	done
}
echo
IFS=$IFSBKP
}
#******************************************************************************#


#******************************************************************************#
#	Monitorig tools
#------------------------------------------------------------------------------#
function transect() {
	top -b -n1 | head -n11 | tail -n5
	df
}
function stag() {
	watch -n3 -d '
	top -b -n1 | head -n11 | tail -n5
	df
	'
}
#******************************************************************************#


#******************************************************************************#
#	Search
#------------------------------------------------------------------------------#
function duck() {
	ques=""
	for word in $@; do ques="$ques+$word"; done
	firefox "https://duckduckgo.com/?q=$ques"
}
#******************************************************************************#


#******************************************************************************#
#	Extract
#------------------------------------------------------------------------------#
function extract()
# Handy Extract Program.
{
	if [ -f $1 ] ; then
		case $1 in
			*.tar.bz2)		tar xvjf $1		;;
			*.tar.gz)		tar xvzf $1		;;
			*.bz2)			bunzip2 $1		;;
			*.gz)			gunzip $1		;;
			*.tar)			tar xvf $1		;;
			*.tbz2)		tar xvjf $1		;;
			*.tgz)			tar xvzf $1		;;
			*.zip)			unzip $1		;;
			*.7z)			7z x $1			;;
			*.rar)			unrar x $1		;;
			*.Z)			uncompress $1	;;
			*)				echo "$0: $1 cannot be extracted via >extract<" ;;
		esac
	else
		echo "$0: Cannot access $1: No such file or directory"
	fi
}
#******************************************************************************#


#******************************************************************************#
#	Welcoming!
#------------------------------------------------------------------------------#
## customize this first message with a message of your choice.
## this will display the username, date, time, a calendar, the amount of users, and the up time.
#clear
## Gotta love ASCII art with figlet
#figlet "Welcome, " $USER;
#echo -e ""
#echo -ne "Today is "; date
#echo -e ""; cal ;
#echo -ne "Up time:"; uptime | awk /'up/'
#echo "";
#******************************************************************************#


#******************************************************************************#
#	Stop Flash from tracking everything you do.
#------------------------------------------------------------------------------#
#	Brute force way to block all LSO cookies \
#	on Linux system with non-free Flash browser plugin
for A in ~/.adobe ~/.macromedia ; do ( [ -d $A ] && rm -rf $A ; ln -s -f /dev/null $A ) ; done
#******************************************************************************#


#******************************************************************************#
#	cpv
#------------------------------------------------------------------------------#
# @see http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/
#
cpv()
{
	strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
	| awk '{
		count += $NF
			if (count % 10 == 0) {
				percent = count / total_size * 100 + 1
				printf "%3d%% [", percent
				for (i=0;i<=percent;i++)
					printf "="
				printf ">"
				for (i=percent;i<=100;i++)
				printf " "
				printf "]\r"
			}
		}
		END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
#******************************************************************************#


#******************************************************************************#
#	trash
#------------------------------------------------------------------------------#
function trash() {
	echo -ne "Delete permanently? [y/N] "
	read ans
	case $ans in
		Y*|y*)
			rmp "$@"
#			echo "deleted"
		;;
		*)
			rmt "$@"
#			echo "trashed"
		;;
	esac
}
#******************************************************************************#


#==============================================================================#

#******************************************************************************#
#	Uploading file to https://transfer.sh/
#------------------------------------------------------------------------------#
transfer() { if [ $# -eq 0 ]; then echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi
tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }; alias transfer=transfer
#******************************************************************************#

#******************************************************************************#
#    Git Completion
#------------------------------------------------------------------------------#
if [ -f ~/.git-completion.bash ]; then
	source ~/.git-completion.bash
fi

export PROMPT_COMMAND="$PROMPT_COMMAND""gitify;"
function gitify() {
	git branch &>/dev/null
	if [[ $? -ne 0 ]]; then
		PS1="$default_PS1"
		reset_git_aliases
		return
	fi

	branch=$(git rev-parse --abbrev-ref HEAD)

        foo=$(pwd)
        bar=$(git rev-parse --show-toplevel | sed "s/[^\/]*$//" | sed "s/^\(.\):/\/\L\1/")
        buz=${foo/$bar/}

	if [[ $ret > 0 ]]; then dimclr=$dimred; else dimclr=$dimwht; fi

	PS1="$txtrst$txtblk$bakcyn{$branch}$txtrst$bldblu:$buz$txtgry > git $txtrst"

	#status=$(git status)

	#echo $status | grep "Untracked files:" &>/dev/null
	#[[ $? -eq 0 ]] && t=$bldred || t=$bldgrn

	#echo $status | grep "Untracked files:" &>/dev/null
	#[[ $? -eq 0 ]] && t=$bldred || t=$bldgrn

	#echo -n -e $txtrst
	#git log --oneline -3

	#PS1="$txtrst$txtblk$bakcyn{$branch}$txtrst$t[t]$bldblu:$buz$txtgry > git $txtrst"

	complete -W "$(echo `git log --format="%h"`;)" diff

	set_git_aliases
}

function set_git_aliases() {
	alias    clone="git clone"      # Clone a repository into a new directory
	alias     init="git init"       # Create an empty Git repository or reinitialize an existing one
	alias      add="git add"        # Add file contents to the index
	alias       mv="git mv"         # Move or rename a file, a directory, or a symlink
	alias    reset="git reset"      # Reset current HEAD to the specified state
	alias       rm="git rm"         # Remove files from the working tree and from the index
	alias   bisect="git bisect"     # Use binary search to find the commit that introduced a bug
	alias     grep="git grep"       # Print lines matching a pattern
	alias      log="git log"        # Show commit logs
	alias     show="git show"       # Show various types of objects
	alias   status="git status"     # Show the working tree status
	alias   branch="git branch"     # List, create, or delete branches
	alias checkout="git checkout"   # Switch branches or restore working tree files
	alias   commit="git commit"     # Record changes to the repository
	alias     diff="git diff"       # Show changes between commits, commit and working tree, etc
	alias    merge="git merge"      # Join two or more development histories together
	alias   rebase="git rebase"     # Forward-port local commits to the updated upstream head
	alias      tag="git tag"        # Create, list, delete or verify a tag object signed with GPG
	alias    fetch="git fetch"      # Download objects and refs from another repository
	alias     pull="git pull"       # Fetch from and integrate with another repository or a local branch
	alias     push="git push"       # Update remote refs along with associated objects

	alias                 am="git am"
	alias              apply="git apply"
	alias            archive="git archive"
	alias              blame="git blame"
	alias             bundle="git bundle"
	alias           cat-file="git cat-file"
	alias        cherry-pick="git cherry-pick"
	alias              clean="git clean"
	alias        commit-tree="git commit-tree"
	alias             config="git config"
	alias      count-objects="git count-objects"
	alias             daemon="git daemon"
	alias           describe="git describe"
	alias          diffindex="git diffindex"
	alias         fastimport="git fastimport"
	alias      filter-branch="git filter-branch"
	alias       for-each-ref="git for-each-ref"
	alias       format-patch="git format-patch"
	alias               fsck="git fsck"
	alias                 gc="git gc"
	alias        hash-object="git hash-object"
	alias               help="git help"
	alias           instaweb="git instaweb"
	alias           ls-files="git ls-files"
	alias         merge-base="git merge-base"
	alias          mergetool="git mergetool"
	alias          read-tree="git read-tree"
	alias             reflog="git reflog"
	alias             remote="git remote"
	alias       request-pull="git request-pull"
	alias           rev-list="git rev-list"
	alias          rev-parse="git rev-parse"
	alias             revert="git revert"
	alias          send-mail="git send-mail"
	alias           shortlog="git shortlog"
	alias           show-ref="git show-ref"
	alias              stash="git stash"
	alias          submodule="git submodule"
	alias                svn="git svn"
	alias       symbolic-ref="git symbolic-ref"
	alias       update-index="git update-index"
	alias         update-ref="git update-ref"
	alias update-server-info="git update-server-info"
	alias        verify-pack="git verify-pack"
	alias         write-tree="git write-tree"

	alias        b="git branch"
	alias        c="git checkout"
	alias        f="git fetch --prune"
	alias        l="git log --oneline --graph --decorate"
	alias       l9="git log -n 9 --oneline --graph --decorate"
	alias      l16="git log -n 16 --oneline --graph --decorate"
	alias        r="git remote"
	alias        s="git commit --dry-run --short"
	alias        t="git diff --cached"
	alias        a="git add"
	alias       aa="git add --update" # (mnemonic: "add all")
	alias    stage="git add"
	alias       ap="git add --patch"
	alias        p="git diff --cached" # (mnemonic: "patch")
	alias       ps="git diff --cached --stat" # (mnemonic: "patch stat")
	alias  unstage="git reset HEAD"
	alias       ci="git commit --verbose"
	alias       ca="git commit --verbose --all"
	alias    amend="git commit --verbose --amend"
	alias        n="git commit --verbose --amend"
	alias        k="git cherry-pick"
	alias       re="git rebase --interactive"
	alias      pop="git reset --soft HEAD^"
	alias     peek="git log -p --max-count=1"
	alias        f="git fetch"
	alias       pm="git pull" # (mnemonic: "pull merge")
	alias       pr="git pull --rebase" # (mnemonic: "pull rebase")
	alias        d="git diff"
	alias       ds="git diff --stat" # (mnemonic: "diff stat")
	alias     hard="git reset --hard"
	alias     soft="git reset --soft"
	alias    scrap="git checkout HEAD --"
	alias  discard="confirm && git reset --hard HEAD"
}

function reset_git_aliases() {
	unalias    clone &>/dev/null
	unalias     init &>/dev/null
	unalias      add &>/dev/null
	unalias       mv &>/dev/null
	unalias    reset &>/dev/null
	unalias       rm &>/dev/null
	unalias   bisect &>/dev/null
	unalias     grep &>/dev/null
	unalias      log &>/dev/null
	unalias     show &>/dev/null
	unalias   status &>/dev/null
	unalias   branch &>/dev/null
	unalias checkout &>/dev/null
	unalias   commit &>/dev/null
	unalias     diff &>/dev/null
	unalias    merge &>/dev/null
	unalias   rebase &>/dev/null
	unalias      tag &>/dev/null
	unalias    fetch &>/dev/null
	unalias     pull &>/dev/null
	unalias     push &>/dev/null

	unalias                 am &>/dev/null
	unalias              apply &>/dev/null
	unalias            archive &>/dev/null
	unalias              blame &>/dev/null
	unalias             bundle &>/dev/null
	unalias           cat-file &>/dev/null
	unalias        cherry-pick &>/dev/null
	unalias              clean &>/dev/null
	unalias        commit-tree &>/dev/null
	unalias             config &>/dev/null
	unalias      count-objects &>/dev/null
	unalias             daemon &>/dev/null
	unalias           describe &>/dev/null
	unalias          diffindex &>/dev/null
	unalias         fastimport &>/dev/null
	unalias      filter-branch &>/dev/null
	unalias       for-each-ref &>/dev/null
	unalias       format-patch &>/dev/null
	unalias               fsck &>/dev/null
	unalias                 gc &>/dev/null
	unalias        hash-object &>/dev/null
	unalias               help &>/dev/null
	unalias           instaweb &>/dev/null
	unalias           ls-files &>/dev/null
	unalias         merge-base &>/dev/null
	unalias          mergetool &>/dev/null
	unalias          read-tree &>/dev/null
	unalias             reflog &>/dev/null
	unalias             remote &>/dev/null
	unalias       request-pull &>/dev/null
	unalias           rev-list &>/dev/null
	unalias          rev-parse &>/dev/null
	unalias             revert &>/dev/null
	unalias          send-mail &>/dev/null
	unalias           shortlog &>/dev/null
	unalias           show-ref &>/dev/null
	unalias              stash &>/dev/null
	unalias          submodule &>/dev/null
	unalias                svn &>/dev/null
	unalias       symbolic-ref &>/dev/null
	unalias       update-index &>/dev/null
	unalias         update-ref &>/dev/null
	unalias update-server-info &>/dev/null
	unalias        verify-pack &>/dev/null
	unalias         write-tree &>/dev/null

	unalias        b &>/dev/null
	unalias        c &>/dev/null
	unalias        f &>/dev/null
	unalias        l &>/dev/null
	unalias        r &>/dev/null
	unalias        s &>/dev/null
	unalias        t &>/dev/null
	unalias        a &>/dev/null
	unalias       aa &>/dev/null
	unalias    stage &>/dev/null
	unalias       ap &>/dev/null
	unalias        p &>/dev/null
	unalias       ps &>/dev/null
	unalias  unstage &>/dev/null
	unalias       ci &>/dev/null
	unalias       ca &>/dev/null
	unalias    amend &>/dev/null
	unalias        n &>/dev/null
	unalias        k &>/dev/null
	unalias       re &>/dev/null
	unalias      pop &>/dev/null
	unalias     peek &>/dev/null
	unalias        f &>/dev/null
	unalias       pm &>/dev/null
	unalias       pr &>/dev/null
	unalias        d &>/dev/null
	unalias       ds &>/dev/null
	unalias     hard &>/dev/null
	unalias     soft &>/dev/null
	unalias    scrap &>/dev/null
	unalias  discard &>/dev/null
}
#******************************************************************************#


#
# ls | while read i
# do
#     echo $i
#     # actions
# done
#


#******************************************************************************#
#	.bashrc autoupdate
#******************************************************************************#

function update_bashrc() {
	cd /tmp
	git clone https://gist.github.com/e1aeb9e3c13fadacb0ef.git &>/dev/null
	if [[ $? -eq 0 ]]; then
		mv -f e1aeb9e3c13fadacb0ef/.bashrc ~/.bashrc &>/dev/null
		rm -f e1aeb9e3c13fadacb0ef -r &>/dev/null
		cd - &>/dev/null
		touch ~/.bashrc_is_new &>/dev/null
		source ~/.bashrc
		echo "Here you are! Your .bashrc is now up to date!"
		return 0
	fi
	echo -e "Oops!! There was a problem updating your .bashrc!\nAre you connected to the internet?"
	cd - &>/dev/null
	return 1
}

if [[ $(date +%u) -eq 1 ]]; then
	if [[ ! -f ~/.bashrc_is_new ]]; then
		echo "Yaaaay! It's monday! Time to update your .bashrc!"
		update_bashrc
	fi
else
	rm ~/.bashrc_is_new &>/dev/null
	true
fi

#******************************************************************************#

#******************************************************************************#
#   Customized settings
#******************************************************************************#
if [ -f ~/.bashrc.custom ]; then
	. ~/.bashrc.custom
fi
#******************************************************************************#