# .bashrc -- Samuel FORESTIER

##
## This file is unmaintained.
## See `.zshrc` instead.
##


# Some HISTORY options
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
HISTCONTROL=ignoredups

# Check the window size after each command
# If necessary, update the values of LINES and COLUMNS
shopt -s checkwinsize

# Match hidden files too with `*` wildcard
shopt -s dotglob


# Colors support for `ls`, `dir`-like and `grep`-like commands
if [ -x /usr/bin/dircolors ]; then
	test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
	alias ls='ls --color=auto'
	alias dir='dir --color=auto'
	alias vdir='vdir --color=auto'
	alias grep='grep --color=auto'
	alias fgrep='fgrep --color=auto'
	alias egrep='egrep --color=auto'
fi


# Colored GCC warnings and errors (important !)
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'


# BASH auto-completion
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
	. /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
	. /etc/bash_completion
  fi
fi


# `ll` alias for `ls` !
alias ll='ls -lAh'

# Let's set a colorful prompt.
PS1='\
\[\033[00m\][\
\[\033[31m\]\u\
\[\033[00m\]@\
\[\033[35m\]\h\
\[\033[00m\]:\
\[\033[34m\]\w\
\[\033[00m\]]\
\[\033[00m\]\$\
 '


# Macro for archives extraction
extract()
{
	if [[ -f $1 ]]; then
		case $1 in
			*.tar.bz2) tar xvjf $1 ;;
			*.tar.gz) tar xvzf $1 ;;
			*.bz2) bunzip2 $1 ;;
			*.rar) unrar x $1 ;;
			*.gz) gunzip $1 ;;
			*.tar) tar xvf $1 ;;
			*.tbz2) tar xvjf $1 ;;
			*.tgz) tar xvzf $1 ;;
			*.zip) unzip $1 ;;
			*.Z) uncompress $1 ;;
			*.7z) 7z x $1 ;;
			*) echo "Don't know how to extract '$1'..." ;;
		esac

	else
		echo "'$1' is not a valid file !"
	fi
}

# Personal macro to live without the f*cking GNOME-keyring which can't handle ED25519 keys...
keys()
{
	if [[ $1 == "up" ]]; then
		# Let's load the keys into the SSH agent, for 1 hour
		ssh-add -t 3600
	elif [[ $1 == "down" ]]; then
		# Let's unload the keys (why would you do that ?)
		ssh-add -D
	else
		# Just print out the loaded keys...
		ssh-add -l
	fi
}