# Author:  Jianqun (https://jianqun.me)
# Updated: 2026-05-07

# Interactive Shell Check

case "$-" in *i* ) ;; * ) return ;; esac

# Bash History

shopt -s histappend

HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=1000

# Bash Completion

if ! shopt -oq posix; then
    if [ -f /usr/share/bash-completion/bash_completion ]; then
        source /usr/share/bash-completion/bash_completion
    fi
fi

# Bash Prompt

PS1=\
'\[\e[1;37m\][ at \[\e[0m\]'\
'\[\e[1;32m\]\h\[\e[0m\]'\
'\[\e[1;37m\] in \[\e[0m\]'\
'\[\e[1;34m\]\w\[\e[0m\]'\
'\[\e[1;37m\] ]\[\e[0m\]'\
'\[\e[1;31m\]$(GIT_PS1_SHOWDIRTYSTATE=1 __git_ps1 " (%s)")\[\e[0m\]'\
'\n\$ '

case "$TERM" in
    alacritty )
        PROMPT_COMMAND="printf '\e[2 q'"
        PS1="\[\e]0;[ at \h in \W ]\$(__git_ps1 ' (%s)') - Alacritty\a\]${PS1}"
        ;;
    xterm* | rxvt* )
        PROMPT_COMMAND="printf '\e[2 q'"
        PS1="\[\e]0;[ at \h in \W ]\$(__git_ps1 ' (%s)')\a\]${PS1}"
        ;;
    tmux* | screen* )
        PROMPT_COMMAND="printf '\e[2 q'"
        ;;
    * )
        ;;
esac

# Bash Readline

bind 'set bell-style none'
bind 'set colored-completion-prefix on'
bind 'set colored-stats on'
bind 'set completion-ignore-case on'
bind 'set menu-complete-display-prefix on'
bind 'set show-all-if-ambiguous on'
bind 'set skip-completed-text on'
bind 'set visible-stats on'
bind '"\t": menu-complete'
bind '"\e[Z": menu-complete-backward'

# Bash Aliases

alias ls='ls -h --classify=auto --group-directories-first --color=auto'
alias grep='grep --color=auto'
alias diff='diff --color=auto'
alias ip='ip --color=auto'
alias less='less -MRX -i --incsearch -x 4'
alias more='more -e'
alias rm='rm -I'
alias cp='cp -i'
alias mv='mv -i'
alias ln='ln -i'
alias df='df -h'
alias du='du -h'
alias free='free -h'
alias tree='tree --dirsfirst'
alias sudo='sudo '
alias sudoedit='sudo $EDITOR'

# Dircolors

if [ -x /usr/bin/dircolors ]; then
    [ -r ~/.dircolors ] && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi

# Lesspipe.sh

[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# GnuPG

export GPG_TTY="$(tty)"

# Fzf

if [ -x /usr/bin/fzf ]; then
    eval "$(fzf --bash)"
    export FZF_DEFAULT_OPTS="--height=14 --layout=reverse-list --border=rounded --info=right --tabstop=4"
fi

# Homebrew

if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
fi

# OpenClaw

if [ -r ~/.openclaw/completions/openclaw.bash ]; then
    source ~/.openclaw/completions/openclaw.bash
fi
