aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc
blob: 6cc3666849fde0e1110743c40ec527c84649e0c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Ensure we're using at least version 2.05
if ! [ -n "$BASH_VERSINFO" ] ; then
    return
elif ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} == 2)) && \
     ((10#${BASH_VERSINFO[1]%%[![:digit:]]*} < 5)) ; then
    return
fi

# Don't do anything if not running interactively
if [[ $- != *i* ]] ; then
    return
fi

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

# Keep around sixteen million lines of history in file
HISTFILESIZE=$((1 << 24))

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

# 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

# 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 ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} >= 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>
    if ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} > 4)) || \
       ((10#${BASH_VERSINFO[1]%%[![:digit:]]*} >= 1)) ; then
        shopt -s checkjobs
    fi

    # Expand variables in directory completion
    if ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} > 4)) || \
       ((10#${BASH_VERSINFO[1]%%[![:digit:]]*} >= 3)) ; then
        shopt -s direxpand
    fi
fi

# Load any supplementary scripts
if [[ -d $HOME/.bashrc.d ]] ; then
    for bashrc in "$HOME"/.bashrc.d/*.bash ; do
        if [[ -e $bashrc ]] ; then
            source "$bashrc"
        fi
    done
    unset -v bashrc
fi