diff options
Diffstat (limited to '.bashrc')
-rw-r--r-- | .bashrc | 88 |
1 files changed, 87 insertions, 1 deletions
@@ -1,2 +1,88 @@ +[ $DEBUG_DOTFILES ] && echo "Loading .bashrc" -complete -C /usr/bin/terraform terraform +# 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-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 autocompletions" +shopt -s histappend + +# 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! + + # Set the username, hostname and path + PS1="\001$SHELLC_F_GREEN\002\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 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 @) + + 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" + 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" +} |