# -*-mode:bash-*- vim:ft=bash # ~/.bashrc # ============================================================================= # Executed by bash for non-login shells. # # See https://www.gnu.org/software/bash/manual/html_node/index.html # shellcheck shell=bash # shellcheck source=/dev/null # If not running interactively, don't do anything. case $- in *i*) ;; *) return;; esac # General # ----------------------------------------------------------------------------- # Check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # Matches filenames in a case-insensitive fashion when doing filename expansion. shopt -s nocaseglob; # If set, the pattern "**" used in a pathname expansion context will # match all files and zero or more directories and subdirectories. #shopt -s globstar # Do not autocomplete when accidentally pressing Tab on an empty line. shopt -s no_empty_cmd_completion; # Do not overwrite files when redirecting using ">" (override this with ">|"). set -o noclobber; # Set preferred editor for local and remote sessions. if [[ -n $SSH_CONNECTION ]]; then export EDITOR='vim' elif command -v mvim > /dev/null; then export EDITOR='mvim' else export EDITOR='vim' fi # Configure less: # F: automatically exit if the entire file can be displayed in first screen. # I: case-insensitive search. # R: Show ANSI colors. # S: Truncate long lines. # X: Prevent clearing the screen when exiting. # See: https://relentlesscoding.com/2019/01/06/make-less-options-permanent-or-the-missing-lessrc/ export LESS="FIRSX" # Make less more friendly for non-text input files. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # History # ----------------------------------------------------------------------------- # Append to the history file, don't overwrite it. shopt -s histappend; # Keep invalid history operation entries. shopt -s histreedit; # Ignore commands that start with spaces, and ignore consecutive duplicates. # This is a verbose way of saying `ignoreboth`. export HISTCONTROL=ignorespace:ignoredups; # Keep a reasonably long history. export HISTSIZE=4096; # Keep even more history lines inside the file, so we can still look up # previous commands without needlessly cluttering the current shell's history. export HISTFILESIZE=16384; # Keep track of the time the commands were executed. # The xterm colour escapes require special care when piping; e.g. "| less -R". export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "; # Allow going up (CTRL+R) and down (CTRL+S) shell history. [[ $- == *i* ]] && stty -ixon # Colors # ----------------------------------------------------------------------------- # Set colors for dark Terminal themes. export CLICOLOR=1; export LSCOLORS=GxFxCxDxBxegedabagaced; # Enable color support of ls. if [ -x /usr/bin/dircolors ]; then # shellcheck disable=SC2015 test -r "$HOME"/.dircolors && eval "$(dircolors -b "$HOME"/.dircolors)" || eval "$(dircolors -b)" fi # Enable colored GCC warnings and errors. export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' # Prompt # ----------------------------------------------------------------------------- # Uncomment for a colored prompt, if the terminal has the capability. #force_color_prompt=yes # Set a fancy prompt (non-color, unless we know we "want" color). case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac if [ -n "${force_color_prompt:?}" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf. color_prompt=yes else color_prompt= fi fi unset force_color_prompt # Set variable identifying the chroot you work in (see default prompt below). if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # Make default first prompt string informative, and optionally colorful. # Basic style: "user@hostname:/current/path$ " # Date style: " # [01 Jan, 14:00:00] user@hostname:/current/path$ " if [ "$color_prompt" = yes ]; then # Basic style PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # Date style PS1="\n\[\033[31m\][\D{%d %b}, \t] ${debian_chroot:+($debian_chroot)}\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "; SUDO_PS1="\n[\D{%d %b}, \t] ${debian_chroot:+($debian_chroot)}\[\e[90;01;41m\]\u@\h\[\e[0m\]:\$PWD\$ "; export SUDO_PS1 else # Basic style PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ " # Date style PS1="\n[\D{%d %b}, \t] $PS1" fi # Xterm # ----------------------------------------------------------------------------- # If this is an xterm set the title to "user@host:dir". case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac # Set Xterm/screen/Tmux title with only a short hostname. # Uncomment this (or set SHORT_HOSTNAME to something else), # Will otherwise fall back on $HOSTNAME. SHORT_HOSTNAME=$(hostname -s) export SHORT_HOSTNAME # Set Xterm/screen/Tmux title with only a short username. # Uncomment this (or set SHORT_USER to something else), # Will otherwise fall back on $USER. export SHORT_USER="${USER:0:8}" # Set Xterm/screen/Tmux title with shortened command and directory. # Uncomment this to set. export SHORT_TERM_LINE=true # Bash-It Framework # ----------------------------------------------------------------------------- # Hide default user from local prompt export DEFAULT_USER="${USER}" # Path to the bash it configuration export BASH_IT="${HOME}/.bash-it" # Lock and Load a custom theme file. # Leave empty to disable theming. # location /.bash_it/themes/ if [ "$color_prompt" = yes ]; then export BASH_IT_THEME='agnoster' fi unset color_prompt # (Advanced): Change this to the name of your remote repo if you # cloned bash-it with a remote other than origin such as `bash-it`. # export BASH_IT_REMOTE='bash-it' # Your place for hosting Git repos. You can use this for private repos. # export GIT_HOSTING='git@git.domain.com' # Don't check mail when opening terminal. unset MAILCHECK # Change this to your console based IRC client of choice. #export IRC_CLIENT='irssi' # Set this to the command you use for todo.txt-cli manager. #export TODO="t" # Set this to false to turn off version control status checking within the # prompt for all themes. export SCM_CHECK=true # Set vcprompt executable path for scm advance info in prompt (demula theme). # See https://github.com/djl/vcprompt #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt # Make Bash-it reload itself automatically after enabling or disabling aliases, # plugins, and completions. # Uncomment this to set. export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1 # Make Bash-it create alias reload. # Uncomment this to set. # export BASH_IT_RELOAD_LEGACY=1 # Load Bash It (if installed). [ -s "${BASH_IT}/bash_it.sh" ] && \. "${BASH_IT}/bash_it.sh" # Command-line shell completions # ----------------------------------------------------------------------------- # Enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then \. /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then \. /etc/bash_completion fi fi # Provide known hosts completions. # See http://surniaulula.com/2012/09/20/autocomplete-ssh-hostnames/ # shellcheck disable=SC2063 _complete_hosts () { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" host_list=$({ for c in /etc/ssh_config /etc/ssh/ssh_config "$HOME"/.ssh/config do [ -r "$c" ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' "$c" done for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts "$HOME"/.ssh/known_hosts do [ -r "$k" ] && grep -E -v '^[#\[]' "$k"|cut -f 1 -d ' '|sed -e 's/[,:].*//g' done sed -n -e 's/^[0-9][0-9\.]*//p' /etc/hosts; }|tr ' ' '\n'|grep -v '*') COMPREPLY=("$(compgen -W "$host_list" -- "$cur")") return 0 } for h in host ping ssh sshs telnet do complete -F _complete_hosts $h done unset h # Provide Homebrew completions (if installed). # See https://docs.brew.sh/Shell-Completion if type brew &> /dev/null; then HOMEBREW_PREFIX="$(brew --prefix)" 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" ]] && \. "$COMPLETION" done fi unset HOMEBREW_PREFIX COMPLETION fi # Provide Chezmoi completions (if installed). # See https://github.com/twpayne/chezmoi/blob/master/docs/REFERENCE.md if command -v chezmoi > /dev/null; then eval "$(chezmoi completion bash)" fi # Development environments # ----------------------------------------------------------------------------- # Enable ASDF Extendable version manager (https://asdf-vm.com). # This should replace all language-secific version managers. ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" if [[ ! -d $ASDF_DIR ]] && type brew &> /dev/null; then ASDF_DIR="$(brew --prefix asdf)" fi [ -s "$ASDF_DIR/asdf.sh" ] && \. "$ASDF_DIR/asdf.sh" # Provide ASDF completions (already loaded if using Homebrew). [ -s "$ASDF_DIR/completions/asdf.bash" ] && \. "$ASDF_DIR/completions/asdf.bash" # Enable Node Version Manager. export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Provide Node completions. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # Enable Python version management. if command -v pyenv > /dev/null; then eval "$(pyenv init -)" fi # Provide Python completions. if command -v pipenv > /dev/null; then eval "$(pipenv --completion)" fi # Load Ruby version management. if command -v rbenv > /dev/null; then eval "$(rbenv init -)" fi # Add Ruby gems to PATH. if command -v ruby > /dev/null && command -v gem > /dev/null; then PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH" fi # Provide Travis CI completions. [ -f "$HOME"/.travis/travis.sh ] && \. "$HOME"/.travis/travis.sh # Register Acquia Dev Desktop if [ -d "/Applications/DevDesktop" ]; then export PATH="$PATH:/Applications/DevDesktop/tools" export PATH="$PATH:/Applications/DevDesktop/drush_9" fi # Provide Drush completions. #[ -f ${HOME}/.drush/drush.bashrc ] && \. ${HOME}/.drush/drush.bashrc # Provide Drush prompt customizations. #[ -f ${HOME}/.drush/drush.prompt.sh ] && \. ${HOME}/.drush/drush.prompt.sh # Varia # ----------------------------------------------------------------------------- # Point ripgrep to its configuration file. # See https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc" # Includes # ----------------------------------------------------------------------------- # Load functions declarations from separate configuration file. if [ -f "$HOME"/.bash_functions ]; then \. "$HOME"/.bash_functions fi # Load alias definitions from separate configuration file. if [ -f "$HOME"/.bash_aliases ]; then \. "$HOME"/.bash_aliases fi # Load custom code from separate configuration file. if [ -f "$HOME"/.bash_extras ]; then \. "$HOME"/.bash_extras fi # Finalization # ----------------------------------------------------------------------------- # Add missing paths to PATH. if [ -d "/usr/local/sbin" ]; then export PATH="/usr/local/sbin:$PATH" fi # Remove any duplicate paths. # See https://stackoverflow.com/questions/11650840/remove-redundant-paths-from-path-variable PATH="$(echo "$PATH" | awk 'BEGIN{RS=":";} {sub(sprintf("%c$",10),"");if(A[$0]){}else{A[$0]=1; printf(((NR==1)?"":":")$0)}}')"; export PATH