#        _ _
#    ___| |_|___ ___ ___ ___
#   | .'| | | .'|_ -| -_|_ -|
#   |__,|_|_|__,|___|___|___|
#

# Colors in pacman and yay
alias pacman='pacman --color=auto'
alias yay='yay --color=auto'

# More Vim aliases == better
alias v='nvim'
alias vi='nvim'
alias vim='nvim'

# modern-unix tools
[ -f "$(which duf)" ] && alias df="duf"
[ -f "$(which fd)" ] && alias find="fd -H"
[ -f "$(which rg)" ] && alias grep="rg"

# cat on wings
alias bat='bat --theme zenburn'

# Run vifmrun for image preview with ueberzug
alias vifm="$HOME/.config/vifm/scripts/vifmrun"

# Configure neovide as gvim alternative
function gvim {
    nohup neovide --multiGrid --disowned $@ >/dev/null 2>&1 &
}

# some ls aliases
alias ll='ls -alh --color=auto --group-directories-first'
alias la='ls -Ah --color=auto --group-directories-first'
alias l='ls -CFh --color=auto --group-directories-first'
alias ls='ls -CFh --color=auto --group-directories-first'

# cd stuff
alias ..='cd ..'
alias ...='cd ../..'

# ripgrep > grep
alias ogrep='/usr/bin/grep --color=auto -i' # keep original grep as ogrep

# default image viewer
alias img=sxiv

# default markdown previewer
alias md=markdown_previewer

# default PDF viewer
alias pdf='zathura --fork'

# source: github.com/sharkdp/hexyl
alias hex=hexyl

# show open ports
alias ports='ss -lust | column -t'
alias netstat='netstat -tulanp'


alias loadX='xrdb $HOME/.Xresources'
alias zzz='systemctl suspend'
alias ZZZ='systemctl hibernate'
alias python-env="source $HOME/.scripts/misc/python-env"

# brightness settings
alias blow='xbacklight -set 10'
alias bmed='xbacklight -set 45'
alias bhi='xbacklight -set 90'



# cd shortcuts
alias cdc='cd $HOME/documents/cloud'
alias cdi='cd $HOME/.config/i3'
alias cdd='cd $HOME/documents'
alias cdD='cd $HOME/downloads'
alias cdt='cd $HOME/documents/tools'
alias cdv='cd $HOME/documents/vms/vagrant-vms'

# copy the current path to clipboard
alias cpwd='xclip -selection clipboard -i <(pwd | tr -d "\n")'

# copy the last command issued to the clipboard
alias clc='fc -ln -1 | tr -d "\n" | sed "s/^\s*//g" | xclip -selection clipboard -i'

alias fcd='cd $(fd -t d | fzf)'
alias cdf='cd $(fd -t d | fzf)'
# ipaddr
alias ipa='ip --brief --color add'

# pipe into ccopy --> clipboard
alias ccopy='xclip -selection clipboard'
alias cpy='xclip -selection clipboard'

# IPS
alias pubip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ip a | grep -Eo 'inet (addr:)?([0-9]*\\.){3}[0-9]*' | grep -Eo '([0-9]*\\.){3}[0-9]*' | grep -v '127.0.0.1'"

# search files with fzf and open them
function sf {
        file=$(fzf --preview='head -n$LINES {}')
            [ "$file" != "" ] && $EDITOR $file
}


# Bash Function Snippets

# process grep
function pg {
        pgrep -fa "$1" | grep -E --color "$1"
}

# Fun
alias makespongebob="python -c 'import sys; makeSpongebob = lambda x: \"\".join([i.upper() if c %2 ==0 else i for c,i in enumerate(x)]);print(makeSpongebob(sys.argv[1]))'"


# Docker Aliases
alias podshell="sudo podman run --rm -i -t --entrypoint=/bin/sh"

function podshellhere() {
    dirname=${PWD##*/}
    sudo podman run --rm -it --entrypoint=/bin/sh -v `pwd`:/${dirname} -w /${dirname} "$@"
}

alias nginxhere="sudo podman run --rm -ti -p 80:80 -p 443:443 -v `pwd`:/srv/data swrzm/nginx"

# Opening a SMB server in the same dir
smbhere() {
    local sharename
    [[ -z $1 ]] && sharename="SHARE" || sharename=$1
    sudo podman run --rm -it -p 445:445 -v "${PWD}:/tmp/serve" swrzm/impacket smbserver.py -smb2support $sharename /tmp/serve
}

# Runner
run() {
    nohup $@ & 2>&1 > /dev/null
}

# ---[it sec stuff]--- #

# Disassemble using objdump
disas() {
        objdump -M intel -d $@
    }
