-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
154 lines (126 loc) · 2.8 KB
/
Copy pathbashrc
File metadata and controls
154 lines (126 loc) · 2.8 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
##
# Exit if not interactive.
[[ $- != *i* ]] && return
##
# Safely add path to PATH environment variable
add_path() {
if [[ -d "${1:-/dev/null}" ]]; then
if [[ "${2:-last}" = "first" ]]; then
PATH="${1}${PATH:+:$PATH}"
else
PATH="${PATH:+$PATH:}${1}"
fi
export PATH
return 0
fi
return 1
}
##
# Return true if user is root
is_root() {
[[ 0 -eq $(id -u) ]] && return 0
return 1
}
##
# Safely include files.
require() {
[[ -f "${1:-/dev/null}" ]] && source "$1";
}
##
# destroy history file.
nuke_history() {
cat /dev/null > $HISTFILE
echo "$(date +%s).$$ ($(id -nu))" >> $HISTFILE.nuked
export HISTFILE=/dev/null
}
##
# returns true if terminal supports color.
terminal_supports_color() {
[[ -x /usr/bin/tput ]] && tput setaf 1 >&/dev/null;
}
##
# grep with less (color support) use with care.
lgrep() {
local clr=always
terminal_supports_color || clr=auto
\grep --color=$clr $@ | \less -R
}
##
# find editor
find_editor() {
local editor=
while [[ 0 < ${#@} ]]; do
editor=$(which $1)
[[ -z "$editor" ]] || break
shift;
done
[[ -z "$editor" ]] &&
echo -n echo No available editor: ||
echo -n $editor
}
##
# Ignore space and duplicates. Store only a single instance of a given command.
export HISTCONTROL=ignoreboth:erasedups
##
# Preferred editor.
export EDITOR=$(find_editor vim vi ed)
export VISUAL="$EDITOR"
##
# customize prompt
if terminal_supports_color; then
dclr="34m"; hclr="32m"; pclr="34m"; ps1="$"
if is_root; then
dclr="36m"
hclr="31;9m"
pclr="31m"
ps1='#'
fi
workdir="\[\033[01;$dclr\]\w\[\033[00m\]"
hostnm="[\[\033[01;$hclr\]\h\[\033[00m\]]"
prompt="\[\033[01;$pclr\]$ps1\[\033[00m\] "
export PS1="$workdir$hostnm$prompt"
unset workdir hostnm prompt dclr hclr pclr ps1
else
export PS1="\w [\h]\\$ "
fi
##
# Append to history, don't overwrite.
shopt -s histappend
##
# Update LINES and COLUMNS environment variables after each command.
shopt -s checkwinsize
##
# Enable color (if applicable)
alias grep='grep --color=auto'
alias ls='ls --color=auto'
##
# Useful on new systems.
alias installrvm='curl -k -L get.rvm.io | bash -s stable'
##
# Nuke history
alias killhistory=nuke_history
##
# info to behave like vi
alias info="info --vi-keys"
##
# control characters for less
alias cless='less -r'
##
# allow colors with less
alias less='less -R'
##
# Add ~/bin to executable path
add_path "$HOME/bin" first
##
# Source RVM if necessery.
require "$HOME/.rvm/scripts/rvm"
##
# Add RVM binaries to PATH.
add_path "$HOME/.rvm/bin"
##
# source some additional bashrc files.
if [ -d "$HOME/.profile.d/" ]; then
for srcfile in $HOME/.profile.d/*; do
require "$srcfile"
done
fi