-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_profile
More file actions
96 lines (70 loc) · 2.48 KB
/
Copy pathbash_profile
File metadata and controls
96 lines (70 loc) · 2.48 KB
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
#!/bin/bash
# ----------------------------------------------------------------------
# | Helper Functions |
# ----------------------------------------------------------------------
enable_programmable_completion() {
# Enable programmable completion features
# http://tldp.org/LDP/abs/html/tabexpansion.html
if [ "$OS" == "osx" ]; then
if [ -f $(brew --prefix)/etc/bash_completion ]; then
source $(brew --prefix)/etc/bash_completion
# Make bash complete the `g` alias, just like it does `git`
complete -o default -o nospace -F _git g
fi
elif [ "$OS" == "ubuntu" ]; then
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
source /etc/bash_completion
fi
fi
}
get_os() {
declare -r OS_NAME="$(uname -s)"
local os=""
if [ "$OS_NAME" == "Darwin" ]; then
os="osx"
# Get Linux distribution
# https://web.archive.org/web/20130929034731/http://linuxmafia.com/faq/Admin/release-files.html
elif [ "$OS_NAME" == "Linux" ] && \
[ -e "/etc/lsb-release" ]; then
os="ubuntu"
fi
printf "%s" "$os"
}
source_bash_files() {
local file=""
local i=""
declare -r -a FILES_TO_SOURCE=(
"bash_aliases"
"bash_exports"
"bash_functions"
"bash_options"
"bash_prompt"
"bash.local" # for local settings that should
# not be under version control
)
for i in ${!FILES_TO_SOURCE[*]}; do
file="$HOME/.${FILES_TO_SOURCE[$i]}"
[ -r "$file" ] && source "$file"
done
}
# ----------------------------------------------------------------------
# | Main |
# ----------------------------------------------------------------------
main() {
# The presence of the OS variable in this scope is important as
# the following functions rely on it (e.g. the sourced files use
# it to determine what to execute)
declare -r OS="$(get_os)"
source_bash_files
enable_programmable_completion
}
main
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Unset functions in order to not pollute the global space
unset -f enable_programmable_completion
unset -f get_os
unset -f main
unset -f source_bash_files
# Clear system messages (e.g.: system copyright notice, the
# date and time of the last login, the message of the day, etc.)
clear