if [[ $- != *i* ]] ; then # Shell is non-interactive, don't do anything. return fi [ $DEBUG_DOTFILES ] && echo "Loading .bashrc" # Load initialization [ $DEBUG_DOTFILES ] && echo " Loading ~/.config/shell/init" source ~/.config/shell/init # Load the sources file, which in turn will source more functionality [ $DEBUG_DOTFILES ] && echo " Loading ~/.config/shell/sources" source ~/.config/shell/sources # Set vi mode [ $DEBUG_DOTFILES ] && echo " Setting vi-mode" set -o vi # Bind some emacs-style bindings in insert mode bind -m vi-insert "\C-a":beginning-of-line bind -m vi-insert "\C-b":backward-char bind -m vi-insert "\C-e":end-of-line bind -m vi-insert "\C-f":forward-char bind -m vi-insert "\C-k":kill-line bind -m vi-insert "\C-l":clear-screen bind -m vi-insert "\C-n":history-search-forward bind -m vi-insert "\C-p":history-search-backward bind -m vi-insert "\C-u":kill-region bind -m vi-insert "\C-y":yank # Configure Bash options [ $DEBUG_DOTFILES ] && echo " Setting Bash options" shopt -s histappend shopt -s progcomp if [ -r "$HOME/.config/shell/vendor/bash/feature-auto-completion/bash_completion" ] then [ $DEBUG_DOTFILES ] && echo " Setting up autocompletion" . "$HOME/.config/shell/vendor/bash/feature-auto-completion/bash_completion" fi export COMP_WORDBREAKS="${COMP_WORDBREAKS//:}" # Set up the prompt [ $DEBUG_DOTFILES ] && echo " Setting PS1" PROMPT_COMMAND=__precmd __precmd() { # Record exit code of previous command immediately local previous_exit=$? # Colors in the Bash prompt should be wrapped in \001 and \002, # (RL_PROMPT_START_INGORE and RL_PROMPT_END_IGNORE) in order to avoid # wrapping issues later in life. It is also *very* important to wrap # things in double quotes for the PS1 coloring to be applied correctly! PS1= # Set the username, hostname and path if [[ 0 < $EUID ]] then PS1+="\001$SHELLC_F_GREEN\002" else PS1+="\001$SHELLC_F_RED\002" fi PS1+="\u\001$SHELLC_RESET_COLOR_F\002" PS1+="\001$SHELLC_F_LIGHTGRAY\002@\001$SHELLC_RESET_COLOR_F\002" PS1+="\001$SHELLC_F_MAGENTA\002\H\001$SHELLC_RESET_COLOR_F\002" PS1+="\001$SHELLC_F_LIGHTGRAY\002:\001$SHELLC_RESET_COLOR_F\002" PS1+="\001$SHELLC_F_BLUE\002\w\001$SHELLC_RESET_COLOR_F\002" # Add venv indicator if [[ -n "$PYTHON_VENV_DIR" ]] then PS1+="\001$SHELLC_F_CYAN\002#$(awk -F/ '{ print $(NF-1) }' <<< "$PYTHON_VENV_DIR")\001$SHELLC_RESET_COLOR_F\002" fi # Add git status if git rev-parse --is-inside-work-tree &> /dev/null then PS1+="\001$SHELLC_F_LIGHTGRAY\002·\001$SHELLC_RESET_COLOR_F\002" # Set coloring of the branch name if [[ "$(git status -uno --porcelain 2> /dev/null)" == "" ]] then PS1+="\001$SHELLC_F_GREEN\002" else PS1+="\001$SHELLC_F_YELLOW\002" fi # Get the branch name local git_branch_name=$(git rev-parse --abbrev-ref HEAD) if [[ "$git_branch_name" == "HEAD" ]] then git_branch_name=$(git rev-parse --short HEAD 2> /dev/null) fi # Set the prompt PS1+="$git_branch_name\001$SHELLC_RESET_COLOR_F\002" fi # Add the exit code of the previous command PS1+=" " if [[ $previous_exit -ne 0 ]] then PS1+="\001$SHELLC_F_RED\002" else PS1+="\001$SHELLC_F_LIGHTGRAY\002" fi PS1+="$(printf "%03i" "$previous_exit")\001$SHELLC_RESET_COLOR_F\002" # Final prompt character PS1+=" \001$SHELLC_F_LIGHTGRAY\002»\001$SHELLC_RESET_FULL\002 \001$CURSOR_STYLE\002" }