#
# ~/.bashrc
#

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

# blesh.sh very cool thing
[[ $- == *i* ]] && source /usr/share/blesh/ble.sh --noattach
force_color_prompt=yes

# aliases
alias ls="eza --long --icons --color $1"
alias workon="source ./bin/activate.fish"

# functions

## yazi wrapper
function y() {
	local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
	yazi "$@" --cwd-file="$tmp"
	IFS= read -r -d '' cwd < "$tmp"
	[ -n "$cwd" ] && [ "$cwd" != "$PWD" ] && builtin cd -- "$cwd"
	rm -f -- "$tmp"
}

## git
parse_git_branch() {
  branch=$(git branch --show-current 2>/dev/null)
  [[ -n "$branch" ]] && echo "($branch)"
}

# set vi session
set -o vi

# variables
export EDITOR="nvim"
export VISUAL="nvim"
USER_COLOR='\[\e[1;32m\]'    # Jasna zieleń
HOST_COLOR='\[\e[1;36m\]'    # Jasny cyjan
SEP_COLOR='\[\e[0;90m\]'     # Szary separator
PATH_COLOR='\[\e[0;33m\]'    # Żółty
GIT_COLOR='\[\e[1;35m\]'     # Jasny fiolet
RESET_COLOR='\[\e[0m\]'

# Prompt PS1
PS1="${USER_COLOR}\u${RESET_COLOR}@${HOST_COLOR}\h${RESET_COLOR} ${SEP_COLOR}|${RESET_COLOR} ${PATH_COLOR}\w${RESET_COLOR} ${GIT_COLOR}\$(parse_git_branch)${RESET_COLOR}\n\$ "

# cool shit

eval "$(atuin init bash)"
eval "$(zoxide init bash)"

# git
gh auth setup-git

# Uruchamianie ssh-agent jeśli nie działa
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
    eval "$(ssh-agent -s)"
fi

# Dodawanie klucza, jeśli nie został jeszcze dodany
if ! ssh-add -l | grep -q "$(basename ~/.ssh/github)"; then
    ssh-add ~/.ssh/github > /dev/null 2>&1
fi


clear
fastfetch --config ~/.config/fastfetch/startup.jsonc

# path
PATH=$PATH:~/.local/bin/

# something to ble.sh

[[ ! ${BLE_VERSION-} ]] || ble-attach
