#
# ~/.bashrc
#

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

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

# additional path variables
export PATH=$PATH:~/.local/bin

### ALIAS' ###
#jokes
alias dog='cat'
alias rr='curl -s -L https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash'	#rickroll

#shutdown and reboot
alias sn='shutdown now'
alias rb='reboot'

# navigation
alias ..='cd ..'
alias ...='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'

#libreoffice
alias writer='libreoffice --writer'
alias calc='libreoffice --calc'
alias impress='libreoffice --impress'

# pacman and pikaur
alias install='sudo pacman -S'
alias uninstall='sudo pacman -Rns'
alias search='sudo pacman -Ss'
alias install-all='sudo pikaur'
alias update='sudo pacman -Syyu'                 	# update only standard pkgs
alias update-all="pikaur -Syu"              		# update standard pkgs and AUR pkgs
alias cleanup='sudo pacman -Rns $(pacman -Qtdq)' 	# remove orphaned packages

# Changing "ls" to "exa"
alias ls='exa -l --color=always --group-directories-first --git' # my preferred listing
alias la='exa -a --color=always --group-directories-firs --git'  # all files and dirs
alias ll='exa -al --color=always --group-directories-first --git'  # long format
alias lt='exa -aT --color=always --group-directories-first --git' # tree listing
alias l.='exa -a | egrep "^\."'

# Colorize grep output (good for log files)
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

# confirm before overwriting something
alias cp="cp -i"
alias mv='mv -i'
alias rm='rm -i'

# git
source ~/.git-completion.bash
alias add='git add'
alias addup='git add -u'
alias addall='git add .'
alias branch='git branch'
alias checkout='git checkout'
alias co='git checkout'
alias clone='git clone'
alias commit='git commit -m'
alias fetch='git fetch'
alias pull='git pull origin'
alias push='git push origin'
alias status='git status'
alias diff='git diff'
alias remote='git remote'
alias ftemplate='git fetch template'
alias mtemplate='git merge template/master --allow-unrelated-histories'
alias log='git log'

#st programs
alias cubeide='~/st/stm32cubeide_1.5.0/stm32cubeide'
alias cubemx='/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX/STM32CubeMX'

### AUTOSTART ###
#vi mode
set -o vi

# >>> neofetch >>>
neofetch
# <<< neofetch <<<

# >>> powerline >>>
function _update_ps1() {
    PS1=$(powerline-shell $?)
}
if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
# <<< powerline <<<

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/paul/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/paul/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/paul/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/paul/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<


### FUNCTIONS ###
# >>> Archive extraction >>>
# usage: ex <file>
ex ()
{
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xjf $1   ;;
      *.tar.gz)    tar xzf $1   ;;
      *.bz2)       bunzip2 $1   ;;
      *.rar)       unrar x $1   ;;
      *.gz)        gunzip $1    ;;
      *.tar)       tar xf $1    ;;
      *.tbz2)      tar xjf $1   ;;
      *.tgz)       tar xzf $1   ;;
      *.zip)       unzip $1     ;;
      *.Z)         uncompress $1;;
      *.7z)        7z x $1      ;;
      *.deb)       ar x $1      ;;
      *.tar.xz)    tar xf $1    ;;
      *.tar.zst)   unzstd $1    ;;
      *)           echo "'$1' cannot be extracted via ex()" ;;
    esac
  else
    echo "'$1' is not a valid file"
  fi
}
# <<< Archive extraction <<<

# >>> cd shortcuts >>>
# "mkcd" to mkdir and then cd into the result
mkcd() { mkdir "$@"&&cd "$@";}
# "cdls" to cd and ls in one go
cdls() { cd "$@"&&ls;}
#cdvim to cd into the directory of a file and open the file in vim
cdvim(){ cd "$(dirname "$@")" && vim "$(basename "$@")";}
# <<< cd shortcuts <<<

# anaconda
source /etc/profile.d/conda.sh
