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

# 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'
#alias neovide='neovide --multigrid'

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

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

# universal opener
function open () {
    xdg-open "$*" &
}


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

# Configure neovide as gvim alternative
#function gvim {
#    neovide --multigrid $@
#}

# 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'
#alias pdf='sioyek'

# 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 -i && $HOME/.scripts/i3/lock.sh'
alias ZZZ='systemctl hibernate -i && $HOME/.scripts/i3/lock.sh'
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" | sed "s/^/\"/;s/$/\"/")'

# 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)"'
alias cdp='cd "$(fd -t d --full-path --maxdepth 3 /home/msc/projects | fzf)"'
# ipaddr
alias ipa='ip --brief --color add'
alias ipr='ip -color --brief route'

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

# IPS
alias pubip="curl -s ipinfo.io | jq -r '.ip'"
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'"


# for weird manjaro stuff
alias fixsudo="cat /etc/sudoers.d/10-installer"

# 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 $@
    }