-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbashrc
78 lines (65 loc) · 1.52 KB
/
bashrc
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
# ~/.bashrc: executed by bash(1) for non-login shells.
# vim: fdm=marker :
# If not running interactively, don't do anything {{{
[ -z "$PS1" ] && return
# }}}
# Timing setup {{{
BASH_TIME_STARTUP=${BASH_TIME_STARTUP:-0}
if [[ $BASH_TIME_STARTUP == 1 ]]; then
# Track the time it takes to load each configuration file and store it a
# per shell file
bash_times_file="/tmp/bashtimes.$$"
echo -n > "/tmp/bashtimes.$$"
fi
# }}}
# Functions library {{{
timed_source()
{
local file="$1"
local before=$(date +%s%N)
source "$file"
local after=$(date +%s%N)
echo "$file $before $after" >> "$bash_times_file"
}
maybe_source_file()
{
[[ -f $1 ]] || return
if [[ $BASH_TIME_STARTUP == 1 ]]
then
timed_source "$1"
else
source "$1"
fi
}
source_dir()
{
local dir=$1
local sourcer
if [[ $BASH_TIME_STARTUP == 1 ]]; then
sourcer='timed_source'
else
sourcer='source'
fi
if [[ -d $dir ]]
then
local conf_file
for conf_file in "$dir"/*
do
if [[ -f $conf_file && $(basename "$conf_file") != 'README' ]]
then
$sourcer "$conf_file"
fi
done
fi
}
# }}}
source_dir ~/.bash.d/vendor/bash-preexec # Source bash-preexec first
source_dir ~/.bash.d/local/before
source_dir ~/.bash.d
source_dir ~/.bash.d/local/after
# Additional files that I generally want to source
maybe_source_file ~/.fzf.bash
# Timing teardown {{{
unset BASH_TIME_STARTUP
unset bash_times_file
# }}}