-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
73 lines (58 loc) · 2.56 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
#!/bin/sh
# clear prompt command
unset PROMPT_COMMAND
# load default variables
[ -f ~/.dotfiles_config ] && source ~/.dotfiles_config
# set alias to allow to reload Bash
alias reload="exec $SHELL -l"
if [[ ! "$BASH_LOAD_DOTFILES" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
return
fi
#### functions #################################################################
# Used to mesure command execution time in seconds
function __measure_exec_time {
if [[ "$BASH_MEASURE_EXEC_TIME" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
t1=$(gdate +%s.%N || date +%s.%N)
fi
$*
if [[ "$BASH_MEASURE_EXEC_TIME" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
t2=$(gdate +%s.%N || date +%s.%N)
runtime=$(printf "%05.2f" $(echo "$t2 - $t1" | bc -l))
echo "${runtime}s : $*"
fi
}
#### initialisation ############################################################
# must be interactive shell
[[ "$-" != *i* ]] && return
# detect type of terminal session
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] || ps -o comm= -p $PPID 2> /dev/null | grep sshd > /dev/null; then
export SESSION_TYPE="remote"
else
export SESSION_TYPE="local"
fi
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#### configuration #############################################################
shopt -s autocd # allows `cd **/qux` to enter `./foo/bar/baz/qux`
shopt -s cdspell # auto-correct typos in path names when using `cd`
shopt -s dotglob # include filenames beginning with a `.` in the results of filename expansion
shopt -s globstar # pattern `**` used in a file name expansion context will match all files and zero or more directories and subdirectories
shopt -s nocaseglob # case-insensitive globbing
# bash completion
[ -f /etc/bash_completion ] && bcpath=/etc || bcpath=/usr/local/etc
if [ -f $bcpath/bash_completion ]; then
__measure_exec_time source $bcpath/bash_completion
fi
unset bcpath
#### resources #################################################################
# load Bash configuration files
for file in ~/.{path,bashrc.,bash_system,bash_prompt,bash_exports,bash_functions,bash_asserts,bash_aliases,bash_completion,bash_extra,bash_custom}*; do
[ -f $file ] && __measure_exec_time source $file
done
# load Profile configuration files
for file in ~/etc/profile.d/*; do
[ -f $file ] && __measure_exec_time source $file
done
unset file
#### path ######################################################################
# make sure PATH variable includes `~/bin` and `~/usr/bin` directories
export PATH=$PATH:~/bin:~/usr/bin