#################################################################################
#
#__  __       _____    _       ____             __ _       
#|  \/  |_   _|__  /___| |__   / ___|___  _ __  / _(_) __ _ 
#| |\/| | | | | / // __| '_ \ | |   / _ \| '_ \| |_| |/ _` |
#| |  | | |_| |/ /_\__ \ | | || |__| (_) | | | |  _| | (_| |
#|_|  |_|\__, /____|___/_| |_(_)____\___/|_| |_|_| |_|\__, |
#        |___/                                        |___/ 
#                                                                by @paramah
#                         
#################################################################################

#Load my environment exports
[ -f ~/.exports ] && source ~/.exports

if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH="${PATH}:${HOME}/.local/bin/"
export PATH="${PATH}:${HOME}/.config/composer/vendor/bin"

# paramah configuration
export PATH="/usr/bin/core_perl:$PATH"
export PATH="/home/paramah/.gem/ruby/2.4.0/bin:$PATH"
export PATH="/home/paramah/.gem/ruby/2.3.0/bin:$PATH"
export PATH="/home/paramah/.gem/ruby/2.5.0/bin:$PATH"
export PATH="/home/paramah/.gem/ruby/2.7.0/bin:$PATH"
export PATH="/home/paramah/.local/bin:$PATH"
export PATH="/home/paramah/.cache/rebar3/bin":$PATH
export PATH=/home/paramah/.captain/bin:$PATH

#Home bin (last always!)
export PATH="/home/paramah/go/bin:$PATH"
export PATH="/var/lib/snapd/snap/bin:$PATH"
export PATH="/home/paramah/bin:$PATH"

#symfony 
export PATH="$HOME/.symfony/bin:$PATH"

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
#source /usr/share/zsh-theme-powerlevel9k/powerlevel9k.zsh-theme
#ZSH_THEME="powerlevel9k/powerlevel9k"
#POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs_joined virtualenv nodeenv)

ZSH_THEME="powerlevel10k/powerlevel10k"

export CHROME_BIN=/usr/bin/chromium
source /usr/bin/virtualenvwrapper.sh

plugins=(
  zsh-autosuggestions
  virtualenvwrapper
  taskwarrior
  timewarrior
  archlinux
  systemd
  themes
  git
  fzf
  aws
  ssh-agent
  #git-flow-completion
  docker 
  golang
  terraform
  aterminal
)



source ~/.zplug/init.zsh

zplug 'ytet5uy4/fzf-widgets'
zplug 'zsh-users/zaw'
zplug "pbar1/zsh-terraform"
zplug 'voronkovich/project.plugin.zsh'
zplug romkatv/powerlevel10k, as:theme, depth:1

# autocomplete on steroids
zstyle ':completion:*' fzf-search-display true

# Map widgets to key
bindkey '^ge' fzf-select-widget
bindkey '^@.' fzf-edit-dotfiles
bindkey '^@c' fzf-change-directory
bindkey '^@n' fzf-change-named-directory
bindkey '^@f' fzf-edit-files
bindkey '^@k' fzf-kill-processes
bindkey '^gs' fzf-exec-ssh
bindkey '^/'  fzf-change-recent-directory
bindkey '^r'  fzf-insert-history
bindkey '^xf' fzf-insert-files
bindkey '^xd' fzf-insert-directory
bindkey '^xn' fzf-insert-named-directory

## Git
bindkey '^@g'  fzf-select-git-widget
bindkey '^@ga' fzf-git-add-files
bindkey '^@gc' fzf-git-change-repository

# GitHub
bindkey '^@h'  fzf-select-github-widget
bindkey '^@hs' fzf-github-show-issue
bindkey '^@hc' fzf-github-close-issue

## Docker
bindkey '^@d'  fzf-select-docker-widget
bindkey '^@dc' fzf-docker-remove-containers
bindkey '^@di' fzf-docker-remove-images
bindkey '^@dv' fzf-docker-remove-volumes

zplug load

source $ZSH/oh-my-zsh.sh

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
   export EDITOR='vim'
else
   export EDITOR='nvim'
fi

export DISABLE_AUTO_TITLE='true'

TMPDIR=/home/paramah/.tmp/

eval "$(jira --completion-script-zsh)"

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

TRAPWINCH() {
  zle && { zle reset-prompt; zle -R }
}


autoload bashcompinit
bashcompinit
dsh(){
    docker exec -it $1 sh -c "stty cols $COLUMNS rows $LINES && sh";
}

dbash(){
    docker exec -it $1 bash -c "stty cols $COLUMNS rows $LINES && bash";
}

_goinside(){
    COMPREPLY=( $(docker ps --format "{{.Names}}" -f name=$2) );
}
complete -F _goinside dsh;
complete -F _goinside dbash;
export goinside;

###################################
#         _ _                     
#    __ _| (_) __ _ ___  ___  ___ 
#   / _` | | |/ _` / __|/ _ \/ __|
#  | (_| | | | (_| \__ \  __/\__ \
# (_)__,_|_|_|\__,_|___/\___||___/
#
##########################################################################################


alias l="tmuxp load -y "
alias dc="docker-compose"
alias d="docker"
alias t="tmux"
alias b="buku --suggest"
alias j="jrnl"
alias g="git"
alias wh="curl wttr.in/Gliwice"

alias drestart="sudo systemctl restart docker"
alias dstop="sudo systemctl stop docker"
alias dstart="sudo systemctl start docker"
#alias ls="exa"
alias yaycc="yay -Sc"
alias frp="frpc -c ~/frpc.ini"

alias mleft="xrandr --output HDMI1 --rotation left"
alias mnormal="xrandr --output HDMI1 --rotation normal"

alias l="sudo systemctl restart docker && tmux kill-server"

alias crl="dbus-send --session --dest=org.Cinnamon.LookingGlass --type=method_call /org/Cinnamon/LookingGlass org.Cinnamon.LookingGlass.ReloadExtension string:'EXTENSION_UUID' string:'APPLET'"

alias easy-rsa="docker run --rm -it -v /home/paramah/myCertificateAuthority:/pki draeath/easyrsa"

# alias cat="bat"
#alias ping='~/bin/prettyping --nolegend'

alias sourcec="docker run --publish 7080:7080 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph --volume /var/run/docker.sock:/var/run/docker.sock sourcegraph/server:2.11.2"

alias hadolint="docker run --rm -i hadolint/hadolint"


dd_telegram-desktop () { # launch telegram and send it to scratchpad
    (/usr/bin/telegram-desktop &)
    sleep 2
    i3-msg '[class="Telegram"] move scratchpad'
}

mattermost-desktop () { # launch telegram and send it to scratchpad
    (/usr/bin/mattermost-desktop &)
    sleep 2
    i3-msg '[class="Mattermost"] move scratchpad'
}

theme () {
    (wal -qi $WALLPAPER)
    (feh --bg-scale $WALLPAPER)
    (~/bin/alawal.sh)
}

alias tf=terraform
alias tfw="terraform workspace"

autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/bin/vault vault

xset b off
#wal -i  ~/Wallpapers/5sense1.jpg
#wal -i ~/Wallpapers/steampunk_1.jpg
#wal -i ~/Wallpapers/steampunk_5.jpg
#wal -i ~/Wallpapers/rail.jpg
#wal -i ~/Wallpapers/forrest_new.jpg
#wal -i ~/Wallpapers/cyberpunk_city.jpg
#xrdb ~/.Xresources 
#sudo sh -c 'echo -n "elantech" > /sys/bus/serio/devices/serio1/protocol'
source <(hcloud completion zsh)
#eval "$(starship init zsh)"
#neofetch
#
eval "$(_JZ_COMPLETE=source_zsh jz)"
eval "$(_HAJDUK_COMPLETE=source_zsh hajduk)"
eval "$(_H_COMPLETE=source_zsh h)"
eval "$(direnv hook zsh)"
eval "$(register-python-argcomplete gitlab)"

alias tf=terraform
alias tfw="terraform workspace"

alias easy-rsa="docker run --rm -it -v /home/paramah/secrets/rsa:/pki -v /home/paramah/.aws:/root/.aws -e AWS_PROFILE=sandbox -e KMS_KEY_ID=test paramah/easyrsa"
alias genpass="< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;"

tfv(){
  terraform validate -var-file=vars/$(terraform workspace show).tfvars $1
}

tfp(){
  terraform plan -var-file=vars/$(terraform workspace show).tfvars $1 
}

tfa(){ 
  terraform apply -var-file=vars/$(terraform workspace show).tfvars $1
}

tfc(){
  terraform console -var-file=vars/$(terraform workspace show).tfvars $1
}


gitc(){
    git commit -a -S $1
}

ec2-list(){
    aws ec2 describe-instances \
        --filter "Name=instance-state-name,Values=running" \
        --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='Name'].Value|[0], LaunchTime, InstanceId]" \
        --output table
}

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

#complete -o nospace -C /usr/bin/terraform terraform

source $HOME/.oh-my-zsh/custom/plugins/fzf-tab-completion/zsh/fzf-zsh-completion.sh

autoload -Uz bashcompinit && bashcompinit
complete -C aws_completer aws

eval "$(_MOLECULE_COMPLETE=source molecule)"
#. ~/.cache/wal/colors.sh
#
#

function prompt_docker_host() {
    if [[ ! -z "${DOCKER_HOST}" ]]; then
        proto="$(echo $DOCKER_HOST | grep :// | sed -e's,^\(.*://\).*,\1,g')"
        url=$(echo $DOCKER_HOST | sed -e s,$proto,,g)
        user="$(echo $url | grep @ | cut -d@ -f1)"
        hostport=$(echo $url | sed -e s,$user@,,g | cut -d/ -f1)
        host="$(echo $hostport | sed -e 's,:.*,,g')"

        p10k segment -b blue -f black -t "${host}"
    fi
}

function prompt_jzmode() {
    if [ -f .jz-mode ]; then
        p10k segment -b '#012845' -f white -t $(cat .jz-mode)
    fi
}

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=docker_host
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=jzmode

decodeuuid() {
    http https://www.uuidtools.com/api/decode/$1 |jq
}

rpg () {
    rpg-cli "$@"
    cd "$(rpg-cli pwd)"
}

mh() {
    xrandr --output DP1-1 --auto --right-of eDP1
    xrandr --output DP1-2 --auto --left-of eDP1
    theme
}
export PAGER=bat
#cat ~/.ideas
