#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# Bash settings
set -o noclobber
shopt -s checkwinsize
export HISTCONTROL=ignorespace

# Color output
export TERM=xterm-color
export GREP_OPTS='--color=auto'
export LS_OPTS='--color=auto -hFN --group-directories-first'
export LESS="--RAW-CONTROL-CHARS -i"

man() {
	env \
		LESS_TERMCAP_mb=$(printf "\e[1;31m") \
		LESS_TERMCAP_md=$(printf "\e[1;31m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[1;32m") \
	man "$@"
}

alias ls='ls ${LS_OPTS}'
alias grep='grep ${GREP_OPTS}'

# Aliases and color output
alias l='ls -l'
alias la='ls -a'
alias ll='ls -la'
alias dusch='du -sch'
alias sorth='sort -hr'

alias woman='man'
alias enby='man'

# Stop Ctrl-S from doing terminally things in vim
vim()
{
	local STTYOPTS="$(stty --save)"
	stty stop '' -ixoff
	command vim "$@"
	stty "$STTYOPTS"
}

vimdiff()
{
	local STTYOPTS="$(stty --save)"
	stty stop '' -ixoff
	command vimdiff "$@"
	stty "$STTYOPTS"
}

alias gvimr='gvim --remote-silent'
alias xo='xdg-open'

alias ps-grep='ps aux | grep'

alias wine32='env WINEARCH=win32 WINEPREFIX="$HOME/.wine32" wine'

# TODO: aliases/functions auslagern?

alias xclip_='xclip -selection clipboard'

xclip-greppassword() {
	grepstr="Password: "
	filename="$1"

	if [ "$#" -ge 2 ]; then
		grepstr="$1"
		filename="$2"
	fi

	grep -m 1 "$grepstr" "$filename" | cut -d " " -f 2 | xclip -r -selection clipboard
}

calc()
{
	echo "$@" | bc
}

#alias su="su -l"

# Create and cd to tmp dir
alias cdtmp='cd $(mktemp -d -p ~/tmp/)'

# yay without parameters does "pacman -Syu" but I don't it to do this
yay() {
	if [ $# -eq 0 ]; then
		echo "error: no operation specified (use -h for help)"
		return 1
	else
		command yay "$@"
	fi
}


# Bash prompt
PS1='[\u@\h \W]\$ '

   TRED='\[\e[0;31m\]' # Red
 TGREEN='\[\e[0;32m\]' # Green
  TBLUE='\[\e[1;34m\]' # Blue
TWHITEB='\[\e[1;37m\]' # White bold
 TRESET='\[\e[0m\]'    # Text Reset

if [[ ${EUID} == 0 ]] ; then
	PS1="${TRED}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
else
	PS1="${TGREEN}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
fi

export PROMPT_DIRTRIM=3

unset TRED TGREEN TBLUE TWHITEB TRESET

