-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdot.bashrc
More file actions
167 lines (151 loc) · 4.25 KB
/
dot.bashrc
File metadata and controls
167 lines (151 loc) · 4.25 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
155
156
157
158
159
160
161
162
163
164
165
166
##
## dotfiles -- Essential Unix Dot-Files
## Copyright (c) 1995-2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
## Distributed under MIT <https://opensource.org/licenses/MIT> license.
##
## ~/.bashrc: bash(1) run-command script
##
# enforce UTF-8 locale
export LC_CTYPE="en_US.UTF-8"
# determine terminal colors
_term_colors=$(tput colors 2>/dev/null)
if [[ -n $_term_colors && $_term_colors -ge 8 ]]; then
# determine terminal color sequences
_col_bl=$'\e[34m'
_col_rd=$'\e[31m'
_col_gr=$'\e[37m'
_col_no=$'\e[0m'
else
# fallback to no coloring
_col_bl=""
_col_rd=""
_col_gr=""
_col_no=""
fi
# customize interactive prompt
shopt -s promptvars
PROMPT_DIRTRIM=11
PS1="╭─┈ ${_col_bl}\\u@\\h${_col_no}:${_col_rd}\${PWD}${_col_no}\n╰─▶ "
PS2="> "
# indicate if last command returned an error exit code
_check_exit_code () {
local code=$?
if [[ $code -gt 0 && $code -lt 126 ]]; then
echo "-bash: ${_col_rd}WARNING${_col_no}: last command terminated with error exit code ${_col_bl}${code}${_col_no}"
fi
}
PROMPT_COMMAND="_check_exit_code"
# perform shell window size checking
if expr $- : ".*i.*" >/dev/null; then
shopt -s checkwinsize
fi
# customize editor/pager handling
export EDITOR=vim
export PAGER="less"
export PAGER_FLAGS=""
alias more="less"
# locate temporary directory
for __tmpdir in "$HOME/tmp" /tmp /var/tmp; do
if [[ -d "$__tmpdir" && -w "$__tmpdir" ]]; then
TMPDIR="$__tmpdir"
break
fi
done
unset __tmpdir
if [[ -z ${XDG_RUNTIME_DIR+x} ]]; then
export XDG_RUNTIME_DIR=$TMPDIR
fi
# customize filesystem handling
umask 022
shopt -s autocd
shopt -s dirspell
shopt -s cdspell
shopt -s no_empty_cmd_completion
shopt -s checkhash
shopt -s globstar
# customize history management
shopt -s cmdhist
shopt -s histappend
shopt -s lithist
HISTSIZE=1000
HISTFILESIZE=1000
HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear"
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
HISTCONTROL="erasedups:ignoredups:ignorespace"
PROMPT_COMMAND="$PROMPT_COMMAND; history -a"
# customize ls(1) command
ls_options=""
ls_pager="$PAGER -X -E"
case $OSTYPE in
*freebsd* ) ls_options="$ls_options -k -q" ;;
*linux* ) ls_options="$ls_options -k -q" ;;
esac
if [[ -n $_term_colors && $_term_colors -ge 8 ]]; then
case $OSTYPE in
*freebsd* )
export LSCOLORS="ExcxcxcxbxcxcxbxbxExEx"
export CLICOLOR_FORCE=1
ls_options="$ls_options -G"
ls_pager="$ls_pager -r"
;;
*linux* )
export LS_COLORS="no=00:fi=00:rs=00:di=01;34:ln=00;32:mh=00;32:or=37;42:mi=37;42:pi=00;32:so=00;32:do=00;32:bd=00;32:cd=00;32:su=00;31:sg=00;31:ex=00;31:ca=00:tw=00:ow=00:st=00:"
ls_options="$ls_options --color=always"
ls_pager="$ls_pager -r"
;;
esac
fi
ls () {
ls_options_extra=""
case $OSTYPE in
*freebsd* ) ls_options_extra="-C" ;;
*linux* ) ls_options_extra="-C" ;;
esac
command ls $ls_options $ls_options_extra ${1+"$@"} | $ls_pager
}
ll () {
command ls $ls_options -l ${1+"$@"} | $ls_pager
}
la () {
command ls $ls_options -l -a ${1+"$@"} | $ls_pager
}
# provide tmux(1) wrapper command
tmux-session () {
local session=default
if [[ $# -ge 1 ]]; then
session="$1"
shift
fi
tmux new-session -A -s "$session" "$@"
}
# determine reasonable search paths
__mkpath () {
eval "unset $1"
for __dir in $2; do
[[ ${__dir: -1} != / ]] && __dir="$__dir/"
for __subdir in $3; do
if [[ -d "$__dir$__subdir" ]]; then
eval "$1=\"\$$1\${$1+:}$__dir$__subdir\""
fi
done
done
eval "export $1"
}
__mkpath PATH "$HOME /opt/local /opt /usr/opkg /usr/local /usr /" "bin sbin"
__mkpath MANPATH "$HOME /opt/local /opt /usr/opkg /usr/local /usr/share /usr " "man"
unset __mkpath
# optionally enable FZF integration
if [[ -f ~/.bash-fzf.rc ]]; then
source ~/.bash-fzf.rc
fi
# optionally enable ENVRC functionality
if [[ -f ~/.bash-envrc.rc ]]; then
source ~/.bash-envrc.rc
if type -t envrc >/dev/null; then
envrc switch -i "$HOME"
fi
fi
# include optional local configuration
if [[ -f ~/.dotfiles/bashrc ]]; then
source ~/.dotfiles/bashrc
fi