install.fairie/home/dot_bashrc
2023-08-08 01:29:21 -04:00

196 lines
6.6 KiB
Bash

#!/usr/bin/env bash
# shellcheck disable=SC1090,SC1091
# Prefer US English
export LANG="en_US"
if [[ "$(hostname)" != *'-minimal' ]]; then
export LC_ALL="en_US.UTF-8"
fi
### Sensible Bash
# Source: https://github.com/mrzool/bash-sensible
[ ! -f "${XDG_DATA_HOME:-$HOME/.local/share}/shell/sensible.bash" ] || . "${XDG_DATA_HOME:-$HOME/.local/share}/shell/sensible.bash"
# Detect support for advanced terminal features
if [ "$0" = 'bash' ] || [ "$0" = '/bin/bash' ]; then
export BASH_SUPPORT=true
fi
### Import Common Settings
[ ! -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/profile.sh" ] || . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/profile.sh"
### Ble.sh
[[ $- == *i* ]] && source "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh" --noattach --rcfile "${XDG_DATA_CONFIG:-$HOME/.config}/blesh/bleshrc"
### /etc/bashrc
[ ! -f /etc/bashrc ] || . /etc/bashrc
### Java (asdf)
[ ! -f "$ASDF_DATA_DIR/plugins/java/set-java-home.bash" ] || . "$ASDF_DATA_DIR/plugins/java/set-java-home.bash"
### Escape if shell not interactive
case $- in
*i*) ;;
*) return;;
esac
### Fig / LC_ALL
if [ "$BASH_SUPPORT" = 'true' ]; then
if [ -f "$HOME/.fig/shell/bashrc.pre.bash" ]; then
. "$HOME/.fig/shell/bashrc.pre.bash"
fi
fi
### Pre-exec
# Source: https://github.com/rcaloras/bash-preexec
if [ -f "$HOME/.local/scripts/pre-exec.sh" ]; then
export __bp_enable_subshells="true"
. "$HOME/.local/scripts/pre-exec.sh"
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }
fi
### History
export HISTFILE="$XDG_STATE_HOME/bash/history"
if [ -d "$HISTFILE" ]; then
# Remove history file if it is incorrectly created as a directory
rm -rf "$HISTFILE"
fi
### Bash Initialization Hooks
if [ "$BASH_SUPPORT" = 'true' ]; then
# Prompt (on bash only)
if [[ "$(hostname)" != *'-minimal' ]]; then
### Styled Terminal
export BASH_IT="${XDG_DATA_HOME:-$HOME/.local/share}/bash_it"
export BASH_IT_THEME="powerline"
if command -v powerline-daemon > /dev/null && [ -f "$BASH_IT/bash_it.sh" ]; then
. "$BASH_IT/bash_it.sh"
elif command -v oh-my-posh > /dev/null; then
# Oh My Posh (See: https://ohmyposh.dev/)
eval "$(oh-my-posh init bash --config "${XDG_CONFIG_HOME:-$HOME/.config}/oh-my-posh/Betelgeuse.omp.json")"
else
# Basic styled terminal
case "$TERM" in
xterm* | rxvt* | Eterm | aterm | kterm | gnome* | alacritty)
PS1="\n \[\033[0;34m\]╭─\[\033[0;31m\]\[\033[0;37m\]\[\033[41m\] $OS_ICON \u \[\033[0m\]\[\033[0;31m\]\[\033[44m\]\[\033[0;34m\]\[\033[44m\]\[\033[0;30m\]\[\033[44m\] \w \[\033[0m\]\[\033[0;34m\] \n \[\033[0;34m\]╰ \[\033[1;36m\]\$ \[\033[0m\]"
;;
esac
fi
else
# Minimal session
! command -v oh-my-posh > /dev/null || eval "$(oh-my-posh init bash --config "${XDG_CONFIG_HOME/.config}/oh-my-posh/Betelgeuse-minimal.omp.json")"
fi
### Bash Completion (Homebrew)
autoload -U +X bashcompinit && bashcompinit
if command -v brew > /dev/null; then
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
. "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
done
fi
fi
### Atuin
! command -v atuin > /dev/null || eval "$(atuin init bash)"
### Carapace
! command -v carapace > /dev/null || source <(carapace _carapace)
### Cod
! command -v cod > /dev/null || . <(cod init $$ bash)
### Google Cloud SDK
[ ! -f "${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.bash.inc" ] || . "$HOMEBREW_PREFIX/share/google-cloud-sdk/path.bash.inc"
### direnv
! command -v direnv > /dev/null || eval "$(direnv hook bash)"
### Emplace
! command -v emplace > /dev/null || . <(emplace init bash)
### hiSHtory
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/hishtory/config.sh" ]; then
export PATH="$PATH:${XDG_CONFIG_HOME:-$HOME/.config}/hishtory"
. "${XDG_CONFIG_HOME:-$HOME/.config}/hishtory/config.sh"
fi
### Hoard
if command -v hoard > /dev/null && [ -f "${XDG_DATA_HOME:-$HOME/.local/share}/hoard/src/shell/hoard.bash" ]; then
. "${XDG_DATA_HOME:-$HOME/.local/share}/hoard/src/shell/hoard.bash"
fi
### iTerm2
[ ! -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/iterm/iterm2.bash" ] || . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/iterm/iterm2.bash"
### Fig
[ ! -f "$HOME/.fig/shell/bashrc.post.bash" ] || . "$HOME/.fig/shell/bashrc.post.bash"
### Mamba Forge (Faster Conda Drop-In Replacement)
# TODO: Add logic for Linux
if [ -f /usr/local/Caskroom/mambaforge/base/bin/conda ]; then
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/Caskroom/mambaforge/base/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/usr/local/Caskroom/mambaforge/base/etc/profile.d/conda.sh" ]; then
. "/usr/local/Caskroom/mambaforge/base/etc/profile.d/conda.sh"
else
export PATH="/usr/local/Caskroom/mambaforge/base/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
fi
### Micro-Mamba
# Generate command: micromamba shell init -s bash -p "${XDG_DATA_HOME:-$HOME/.local/share}/micromamba"
# TODO: Ensure Linux support
if [ -f /usr/local/bin/micromamba ]; then
# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE='/usr/local/bin/micromamba';
export MAMBA_ROOT_PREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/micromamba";
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
else
alias micromamba="$MAMBA_EXE" # Fallback on help from mamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<
fi
### Navi (Ctrl+G)
! command -v navi > /dev/null || eval "$(navi widget bash)"
### SDKMan
if command -v brew > /dev/null && command -v sdkman-cli > /dev/null; then
export SDKMAN_DIR="$(brew --prefix sdkman-cli)/libexec"
. "$SDKMAN_DIR/bin/sdkman-init.sh"
elif [ -f "$SDKMAN_DIR/bin/sdkman-init.sh" ]; then
export SDKMAN_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/sdkman"
. "$SDKMAN_DIR/bin/sdkman-init.sh"
fi
### Up
[ ! -f "${XDG_DATA_HOME:-$HOME/.local/share}/up/up.sh" ] || . "${XDG_DATA_HOME:-$HOME/.local/share}/up/up.sh"
### Vault
! command -v vault > /dev/null || complete -C vault vault
### zoxide
if command -v zoxide > /dev/null; then
eval "$(zoxide init bash)" > /dev/null
else
alias z='cd'
fi
### Ble.sh
[[ ${BLE_VERSION-} ]] && ble-attach
fi