# MiniServer shell setup, sourced from ~/.bashrc (added by shell/setup.sh).
# Anything in ~/.bashrc after the line that sources this file overrides it.

# Only for interactive shells
[[ $- != *i* ]] && return

MINISERVER_SHELL="$HOME/.local/share/MiniServer/shell"

# AI agents such as opencode and hermes run sandboxed (see sandbox/agent), so
# sandbox/bin must come before the directories holding their real commands
SANDBOX_BIN="$HOME/.local/share/MiniServer/sandbox/bin"
PATH="$SANDBOX_BIN:${PATH//$SANDBOX_BIN:/}"

# History: keep a lot of it, skip duplicates, and don't let shells overwrite
# each other's history on exit
shopt -s histappend
HISTCONTROL=ignoreboth
HISTSIZE=32768
HISTFILESIZE="$HISTSIZE"

if [[ ! -v BASH_COMPLETION_VERSINFO && -f /usr/share/bash-completion/bash_completion ]]; then
  source /usr/share/bash-completion/bash_completion
fi

source "$MINISERVER_SHELL/aliases"
source "$MINISERVER_SHELL/functions"

# Prompt. Uses MiniServer's starship config unless you have your own.
if [[ $TERM != "dumb" ]] && command -v starship &> /dev/null; then
  [[ -f "$HOME/.config/starship.toml" ]] || export STARSHIP_CONFIG="$MINISERVER_SHELL/starship.toml"
  eval "$(starship init bash)"
fi

# z <part of a path> jumps to a directory you've visited before
if command -v zoxide &> /dev/null; then
  eval "$(zoxide init bash)"
fi

# Ctrl-R fuzzy history search, Ctrl-T to insert a file path, Alt-C to cd
if [[ -f /usr/share/fzf/key-bindings.bash ]]; then
  source /usr/share/fzf/key-bindings.bash
fi
