# set zellij tab title
function current_dir() {
    local current_dir=$PWD
    if [[ $current_dir == $HOME ]]; then
        current_dir="~"
    else
        current_dir=${current_dir##*/}
    fi

    echo $current_dir
}

function change_tab_title() {
    local title=$1
    command nohup zellij action rename-tab $title >/dev/null 2>&1
}

function set_tab_to_working_dir() {
    local result=$?
    local title=$(current_dir)

    change_tab_title $title
}

function set_tab_to_command_line() {
    local cmdline=$1
    change_tab_title $cmdline
}

if [[ -n $ZELLIJ ]]; then
    autoload -Uz add-zsh-hook
    add-zsh-hook precmd set_tab_to_working_dir
    add-zsh-hook preexec set_tab_to_command_line
fi

# git aliases

function git_aliases() {
    echo "git aliases:"
    echo "\tgs:    status -sb"
    echo "\tgl:    log --oneline"
    echo "\tglast: log -1 HEAD --stat"
    echo "\tgds:   diff --staged"
}

alias gs="git status -sb"
alias gl="git log --oneline"
alias glast="git log -1 HEAD --stat"
alias gds="git diff --staged"

# load Cargo
if [ -f "$HOME/.cargo/env" ]; then
	. "$HOME/.cargo/env"
fi

# load Guix
export GUIX_PROFILE="/home/nora/.config/guix/current"
if [ -f "$GUIX_PROFILE/etc/profile" ]; then
	. "$GUIX_PROFILE/etc/profile"
fi

# load Guix stuff, if it exists
if [[ -d "$HOME/.zsh/functions" ]]; then
	export fpath=(~/.zsh/functions $fpath)
	autoload -U compinit && compinit
fi

export NOTESDIR="$HOME/Notes"
export PATH="$HOME/.bin:$HOME/.local/bin:$NOTESDIR/bin:$HOME/src/go/bin:$PATH"
export PATH="/sbin:$PATH"
export GOPATH="$HOME/src/go"

function set_win_title(){
	echo -ne "\033]0;\007"
}

precmd_functions+=(set_win_title)

# start zellij
if [[ -v "$WITHZELLIJ" && "$TERM_PROGRAM" != "vscode" ]]; then
  eval "$(zellij setup --generate-auto-start zsh)"
fi

fortune

