#PATHs
if [ -d "$HOME/.local/bin" ]; then
    export PATH="$HOME/.local/bin:$PATH"
fi

if [ -f "$HOME/.dotfiles-dir" ]; then
    source "$HOME/.dotfiles-dir"
fi

if [ -f "$HOME/.bash_functions" ]; then
    source "$HOME/.bash_functions"
fi

# User profiles
source $HOME/.profile
# Define $POWERLINE_ROOT
if [ -f $HOME/.profile.local ]; then
    source $HOME/.profile.local
fi

if [ -n "$DOTFILES_DIR" ] && [ -d "$DOTFILES_DIR" ]; then
    # Gruvbox colors
    [[ -f "$DOTFILES_DIR/dependencies/gruvbox/gruvbox_256palette.sh" ]] && source "$DOTFILES_DIR/dependencies/gruvbox/gruvbox_256palette.sh"
fi

# Italic support
if [ -f $HOME/.xterm-256color-italic.terminfo ]; then
    tic $HOME/.xterm-256color-italic.terminfo
fi
if [ -f $HOME/.screen-256color-italic.terminfo ]; then
    tic $HOME/.screen-256color-italic.terminfo
fi

# Use neovim where available
if [[ $(program_installed neovim) == 1 ]]; then
    alias vim='nvim'
fi

# fzf fuzzy finder
if [[ $(program_installed fzf) == 1 ]]; then
    # TODO: This is broken when fzf is old, should include a local copy
    eval "$(fzf --bash)"
fi

# # Preferred editor for local and remote sessions
export EDITOR='vim'

# Powerline
set_powerline_bash_sources
found=0
for index in ${!POWERLINE_BASH_SOURCES[@]}; do
    file="${POWERLINE_BASH_SOURCES[index]}"
    if [[ -a $file ]]; then
        # echo "Sourcing Powerline binding: $file"
        # TODO: This is broken when powerline not in chosen python path
        source $file
        found=1
        break
    fi
done
if [ $found -eq 0 ]; then
    echo "Powerline binding not found."
    echo "Please set \$POWERLINE_ROOT in .profile.local"
fi
