aboutsummaryrefslogblamecommitdiff
path: root/bash/bashrc
blob: c2055feb56e389c511342dc00093fb5e785a71cf (plain) (tree)
1
2
3
4
5
6
7
8


                                                                               


                                                    
          
 





                                    
                                                 
                                   
 

                                                    
 

                                                     
 
                                                     
                      
 
                                           
                        
 

                              
 
                  
                                   
 
                                                  
                               
 


                                          


                                                           
                                      
                
                                
                  
                                                
                     
                                                  
                
                                      
                

                                         
                                  
                
                                           
                   



                                                          

                                          
                                           
                 
                                              
                                
                                           
                 

                                                      

                                        

                                               
                                   
 



                                                
 
                                                                       
                                                                         
                                                   
 
                                                                        
                                                   
  
 


                                                                            
                                                                  
 

                                                                               
                                              
                                
    
           
















                                                           
# Ensure we're using at least version 2.05. Weird arithmetic syntax needed here
# due to leading zeroes and trailing letters in some 2.x version numbers (e.g.
# 2.05a).
[ -n "$BASH_VERSINFO" ] || return
((BASH_VERSINFO[0] == 2)) &&
    ((10#${BASH_VERSINFO[1]%%[![:digit:]]*} < 5)) &&
    return

# Make sure the shell is interactive
case $- in
    *i*) ;;
    *) return ;;
esac

# Don't do anything if running a restricted shell
shopt -q restricted_shell && return

# Keep around four thousand lines of history in file
HISTFILESIZE=$((1 << 12))

# Keep around one thousand lines of history in memory
HISTSIZE=$((1 << 10))

# Ignore duplicate commands and whitespace in history
HISTCONTROL=ignoreboth

# Keep the times of the commands in history
HISTTIMEFORMAT='%F %T  '

# Don't warn me about new mail
unset -v MAILCHECK

# Never beep at me
setterm -bfreq -blength 2>/dev/null

# Turn off flow control and control character echo
stty -ixon -ctlecho 2>/dev/null

# Don't let anyone write(1) to my terminal
mesg n

# Don't allow the creation of aliases, functions are better
enable -n alias unalias

# Autocorrect fudged paths in cd calls
shopt -s cdspell
# Update the hash table properly
shopt -s checkhash
# Update columns and rows if window size changes
shopt -s checkwinsize
# Put multi-line commands onto one line of history
shopt -s cmdhist
# Include dotfiles in pattern matching
shopt -s dotglob
# Don't use aliases, functions are better
shopt -u expand_aliases
# Enable advanced pattern matching
shopt -s extglob
# Append rather than overwrite Bash history
shopt -s histappend
# Repeat the line on failed history expansion
shopt -s histreedit
# Repeat the expanded line on successful history expansion
shopt -s histverify
# Don't use Bash's builtin host completion
shopt -u hostcomplete
# Don't warn me about new mail all the time
shopt -u mailwarn
# Ignore me if I try to complete an empty line
shopt -s no_empty_cmd_completion
# Use programmable completion, if available
shopt -s progcomp
# Warn me if I try to shift when there's nothing there
shopt -s shift_verbose
# Don't use PATH to find files to source
shopt -u sourcepath

# These options only exist since Bash 4.0-alpha
if ((BASH_VERSINFO[0] >= 4)) ; then

    # Autocorrect fudged paths during completion
    shopt -s dirspell
    # Enable double-starring paths
    shopt -s globstar

    # Warn me about stopped jobs when exiting; only if >=4.1 due to bug
    # <https://lists.gnu.org/archive/html/bug-bash/2009-02/msg00176.html>
    ((BASH_VERSINFO[1] >= 1)) && shopt -s checkjobs

    # Expand variables in directory completion; only available since 4.3
    ((BASH_VERSINFO[1] >= 3)) && shopt -s direxpand
fi

# If COMP_WORDBREAKS has a value, strip all colons from it; this allows
# completing filenames correctly, since an unquoted colon is not a syntactic
# character: <http://tiswww.case.edu/php/chet/bash/FAQ> (E13)
[[ -n $COMP_WORDBREAKS ]] && COMP_WORDBREAKS=${COMP_WORDBREAKS//:}

# Load POSIX shell functions, Bash-specific scripts, and Bash completion files,
# in that order
for sh in "$ENV" "$HOME"/.bashrc.d/*.bash ; do
    [[ -e $sh ]] && source "$sh"
done
unset -v sh

# If we have dynamic completion loading (Bash>=4.0), use it
if ((BASH_VERSINFO[0] >= 4)) ; then
    _completion_loader() {
        [[ -n $1 ]] || return
        compspec=$HOME/.bash_completion.d/$1.bash
        [[ -f $compspec ]] || return
        source "$compspec" >/dev/null 2>&1 && return 124
    }

# If not, load all of the completions up now
else
    for sh in "$HOME"/.bash_completion.d/*.bash ; do
        [[ -e $sh ]] && source "$sh"
    done
    unset -v sh
fi