aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc
blob: 16669adfa9237581a28e5a1eb53f685796a05447 (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
# Make sure the shell is interactive
case $- in
    *i*) ;;
    *) return ;;
esac

# Don't do anything if restricted, not even sourcing the ENV file
# Testing $- for "r" doesn't work
# shellcheck disable=SC2128
[ -n "$BASH_VERSINFO" ] && shopt -q restricted_shell && return

# Clear away all aliases; we do this here rather than in $ENV because the ksh
# family of shells relies on aliases to implement certain POSIX utilities like
# fc(1) and type(1)
unalias -a

# If ENV is set, source it to get all the POSIX-compatible interactive stuff;
# we should be able to do this even if we're running a truly ancient Bash
[ -n "$ENV" ] && . "$ENV"

# 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).
# shellcheck disable=SC2128
[ -n "$BASH_VERSINFO" ] || return
((BASH_VERSINFO[0] == 2)) &&
    ((10#${BASH_VERSINFO[1]%%[!0-9]*} < 5)) &&
    return

# Keep around 32K lines of history in file
HISTFILESIZE=$((1 << 15))

# Ignore duplicate commands and whitespace in history
HISTCONTROL=ignoreboth

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

# Use a more compact format for the time builtin's output
TIMEFORMAT='real:%lR user:%lU sys:%lS'

# 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
# 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
# Use Bash's builtin host completion
shopt -s hostcomplete
# Don't change newlines to semicolons in history
shopt -s lithist
# 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

# Load Bash-specific startup files
for sh in "$HOME"/.bashrc.d/*.bash ; do
    [[ -e $sh ]] && source "$sh"
done
unset -v sh