-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_bashrc
More file actions
203 lines (175 loc) · 7.19 KB
/
dot_bashrc
File metadata and controls
203 lines (175 loc) · 7.19 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env bash
# vim: ai tw=74 fen fdm=marker nospell fmr={,} sw=4
# shellcheck disable=SC2155
#
######## KMZ big huge .bashrc {
# This file is rewritten from scratch in February 2026, AGAIN
# REQUIRES bash version >= 2.04
#
# NOTE!!!! Don't make changes to this file for a single machine. Use
# .bashrc.local. See "Local Customisations" below.
#
####### General
#
# This file is designed on the assumption that bash is NOT our login
# shell. If it was then the env variable setting should be in the
# .bash_profile file, not the .bashrc. I've made a special effort to keep
# the number of external calls to a minimum
#
####### Local Customisations
#
# It's best not to change this file on a machine-by-machine basis. For
# local extensions this file calls ~/.bashrc.local if it exists. It's
# called twice: once before all processing with a single parameter ($1)
# "pre" and once after all processing with a single parameter "post".
#
# In addition, a number of variables are set and are available for use by
# the ~/.bashrc.local script. These variables are UNset before .bashrc
# exits, so they are not available once the shell is interactive.
#
# The variables set by this script are:
# _debugging Manually set (see below) to "1" if
# parts of this and called scripts
# should be verbose in their output.
# Unset otherwise. NOTE that some
# non-interactive tools (e.g. rsync)
# get confused by stuff being
# printed at shell startup so
# normally this should be OFF.
#
# _shell_is_interactive Set to "1" if this is an interactive
# session, and unset otherwise. No
# output should be produced if this
# is set.
#
# }
######## Set up some variables for later {
#
# NOTE: If a variable is added here it should be unset at the end of the
# file!
#
# _debugging=1
#
# $- contains the options provided to the shell
[[ $- == *i* ]] && _shell_is_interactive=1
# }
# Make the first call on the local settings file
[ -r "${HOME}/.bashrc.local" ] && source "${HOME}/.bashrc.local" pre
# PATH manipulation was simplified, it probably shouldn't be touched at all
PATH=${PATH}:/usr/local/bin:${HOME}/.local/bin
######## Clean up the PATH {
#
# PATH and similar vars are cleaned by dropping non-existant dirs
# and duplicates while keeping the order
#
function pathclean() {
local -a newpathcomps # Array of new path components
local -i alreadyseen # Have we already seen this component?
local component # Current component we're looking at
local -i i # loop var
local thevar=$1 # The NAME of the variable we're cleaning
# Clean up the PATH
# Expunge double /s and make : into a space. Unfortunatly, this breaks
# on path entries with a space in them, as happens in the Cygwin/WSL
# environments with the fabulous "Program Files" directory, so we have
# to kludge spaces into | and then back again...
#
for component in $(echo "${!thevar}" | sed -e 's/ /|/g' -e 's/:/ /g' -e 's#//#/#g'); do
if [[ -d "${component//|/ }" ]]; then
# The directory exists, lets check we haven't already seen it
alreadyseen=0
i=0
while ((i < ${#newpathcomps[*]})); do
if [[ ${newpathcomps[i]} == "$component" ]]; then
alreadyseen=1
break
fi
((i = i + 1))
done
if ((!alreadyseen)); then
newpathcomps[i]=$component
fi
fi
done
# I'm just not game to wrap this line!
eval "$thevar=\"$(echo "${newpathcomps[*]}" | sed -e's/ /:/g' -e 's/|/ /g')\""
}
pathclean PATH
pathclean MANPATH
pathclean LD_LIBRARY_PATH
export PATH MANPATH LD_LIBRARY_PATH
# }
######## Shell options {
#
# Set my preferred options
shopt -s autocd cdspell checkjobs checkwinsize cmdhist dirspell dotglob histreedit globstar histappend nocaseglob
# Also, disable flow control (Ctrl-S and Ctrl-Q) -- who wants that anyway?
stty -ixon
# If I hit <tab> on a blank line, I DON'T want to see a list of all the
# comands in my PATH - who would EVER want that?? This option appeared in
# bash 2.04, so it's not in the Solaris 8 version of bash. Rather than
# checking for the version, check for the existance of the option:
[[ $(shopt) == *no_empty_cmd_completion* ]] &&
shopt -s no_empty_cmd_completion
# Only put duplicate lines in the history once, and don't record in
# history commands that start with at least one space
HISTCONTROL=ignoreboth,erasedups
# }
######## This section is only for interactive shells {
if [[ $_shell_is_interactive == 1 ]]; then
# Prompt and other terminal settings {
# We need extglob turned on, so save the current value
declare oldextglob=$(shopt extglob)
shopt -s extglob
# Declare some variables to work with
# declare settitle
declare red=$(tput setaf 1)
declare green=$(tput setaf 2)
declare blue=$(tput setaf 4)
declare yellow=$(tput setaf 3)
declare reset=$(tput sgr0)
# set up complicated prompt stuff based on terminal type
case $TERM in
*rxvt* | dtterm* | st* | *xterm* | screen* | linux | tmux*)
# These terminals have a title that can be set.
# This magic came from one of the linux HOWTOs
settitle='\[\033]0;\h: \w\007\]\h:\W\$ '
case $TERM in
*rxvt* | *xterm* | dtterm*)
settitle="\[\033]0;\h: \w\007\]"
;;
screen* | tmux*)
# # for screen/tmux I want to set the window title to 'local' on a localhost,
# # otherwise to ssh-dictated user@host line
# settitle='\[\033k\h\033\\\033]0;\w\007\]'
settitle='\[\033klocal\033\\\]'
;;
esac
PS1=${settitle}'\[${yellow}\][\t] \[${green}\]\u@\h\[${reset}\] \[${blue}\]\W \[$(test "$?" -ne 0 && echo -ne ${red})\]\$ \[${reset}\]'
;;
esac
# Remove any exporting of PS1 since it looks hideous in other shells and
# bash will just re-read this file anyway
# export -n PS1
PROMPT_COMMAND=${PROMPT_COMMAND=history -a}
export PROMPT_COMMAND
# set extglob back to how we found it
[[ $oldextglob == *off ]] && shopt -u extglob
unset oldextglob
# }
######## Aliases {
# Main aliases "rebash" and "realias" that help with profile development
# Let me easily re-run this in case of a new installation or change to this
# file. I know, how lazy is this?
alias rebash='source ${HOME}/.bashrc'
alias realias='source ${HOME}/.bashrc.aliases'
# Put the rest of stuff that you want aliased in .bashrc.aliases file
[ -r "${HOME}/.bashrc.aliases" ] && source "${HOME}/.bashrc.aliases"
# }
fi # End of interactive-only section
# }
# Make the last call on the local settings file
[ -r "${HOME}/.bashrc.local" ] && source "${HOME}/.bashrc.local" post
######## Clean up
unset _shell_is_interactive
unset _debugging