-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_bashrc
More file actions
333 lines (295 loc) · 8.32 KB
/
dot_bashrc
File metadata and controls
333 lines (295 loc) · 8.32 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# vim: set filetype=bash :
# NOTE:
# Don't use chezmoi templates for .bashrc as I want to be able to edit this
# without caveats. Must still be generic.
# If the convenience of templates is nice, use additional files and source them
# here.
#
# Add dir to path with check that the dir exists and that it isn't in already
# in path.
# Returns 0 if the dir existed.
add_to_path() {
if [ "$#" -eq 1 ]; then
if [ -d "$1" ]; then
case ":${PATH}:" in
*":${1}:"*) ;; # already in path
*) export PATH="${1}:${PATH}"
esac
return 0
fi
fi
return 1
}
tmp="${HOME}/.bashrc_chezmoi_generated"
if [ -f "$tmp" ]; then
. "$tmp"
fi
tmp=
case "${dz_os_name,,}" in
mac) eval `/usr/lib/path_helper -s`;;
*);;
esac
#
# Local settings to load early (not tracked in dotfiles).
#
if [ -f "${HOME}/.bashrc_local_early" ]; then
. "${HOME}/.bashrc_local_early"
fi
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth:erasedups
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=10000
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# When changing directory small typos can be ignored by bash
shopt -s cdspell
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar
# case-insensitive filename globbing
shopt -s nocaseglob
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
ps1_os_name="${dz_os_name:-"${SHELL}"}" # clear that something went wrong
if [ -n "$dz_os_name" ]; then
case "${dz_os_name,,}" in
*mac*) ps1_os_color="01;37" ;; # white
*ubuntu*) ps1_os_color="01;31" ;; # red
*arch*) ps1_os_color="01;36" ;; # cyan
*) ps1_os_color="01;32" ;; # green
esac
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}[\[\033[${ps1_os_color}m\]${ps1_os_name}\[\033[00m\]]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}[${MY_OS}]:\w\$ '
fi
unset color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}wsl: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
export MANPAGER="less -R --use-color -Dd+r -Du+b"
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
# linux
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
# Mac (intel and arm):
elif [ -f /usr/local/etc/bash_completion ]; then
. /usr/local/etc/bash_completion
elif [ -f /opt/homebrew/etc/profile.d/bash_completion.sh ]; then
. /opt/homebrew/etc/profile.d/bash_completion.sh
fi
fi
# Use the XDG env vars.
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
[ -d "${XDG_CONFIG_HOME}" ] || mkdir -p "${XDG_CONFIG_HOME}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
[ -d "${XDG_CACHE_HOME}" ] || mkdir -p "${XDG_CACHE_HOME}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
[ -d "${XDG_DATA_HOME}" ] || mkdir -p "${XDG_DATA_HOME}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-${HOME}/.local/state}"
[ -d "${XDG_STATE_HOME}" ] || mkdir -p "${XDG_STATE_HOME}"
case "$XDG_DATA_DIRS" in
*"$XDG_DATA_HOME"*) ;; # XDG_DATA_HOME already appended.
*)
export XDG_DATA_DIRS="${XDG_DATA_HOME}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
;;
esac
# Set PATH so it includes user's private bin if it exists.
add_to_path "${HOME}/.local/bin"
add_to_path "${HOME}/.local/bin/scripts"
# Extra bin's
# Dlang: add compilers (latest installed) to PATH.
if [ -f "${HOME}/dlang/install.sh" ]; then
for c in ldc dmd; do
tmp="$("${HOME}/dlang/install.sh" get-path "$c" 2>/dev/null)"
if [ "$?" -eq 0 ] && [ -n "tmp" ]; then
PATH="$(dirname "$tmp"):${PATH}"
fi
tmp=
done
fi
if command -v ldc2 >/dev/null; then
alias ldc=ldc2
fi
# Go
# Set GOPATH for local packages in .config with:
add_to_path "/usr/local/go/bin"
# go env -w GOPATH="${XDG_DATA_HOME}/go" (only needs to be set once).
# Add go programs to PATH; where $GOPATH/bin points (set in .config/go/env).
add_to_path "${XDG_DATA_HOME}/go/bin"
# Adjust PS1 for subshells that would be easy to forget (don't show multiple
# times in nested shells).
if [ "$CHEZMOI" = "1" ]; then
case "$PS1" in
*"(chezmoi)"*) ;;
*)
PS1="(chezmoi)${PS1}";;
esac
fi
# Indicate last command success by color. Removes last 3 chars from
# PS1: '<PS1...> $ ' => becomes something like '<PS1...>'+'\n$ '
ps1_prompt() {
local e=$?
if [ "$e" -eq 0 ]; then
printf '\033[0;32m'
else
printf '\033[0;31m'
fi
return "$e"
}
PS1="\n${PS1::-3}\n"'\[$(ps1_prompt)\]'"\$\[\033[0m\] "
#
# Helpers
#
# Necessary for gpg unlock prompt to work.
export GPG_TTY="$(tty)"
alias ls='ls -FG' # G=color, F=trailing type indicator (dir=/ exe=*, ...)
if command -v eza >/dev/null; then
# Reminder to myself: --icons flag exists
alias l='eza'
else
alias l='ls'
fi
alias ll='l -l'
alias la='l -a'
alias lal='l -la'
alias lla='l -la'
alias l1='l -1'
alias less='less -R'
alias df='df -h' # human readable
alias du='du -h -d 1' # human readable, current dir only
alias hexdump='hexdump -C' # "regular" output style for manual work
if command -v nvim >/dev/null; then
alias vim='nvim'
alias v='nvim'
export EDITOR='nvim'
fi
if command -v hexyl >/dev/null; then
alias hex='hexyl'
fi
if command -v batman >/dev/null; then
eval "$(batman --export-env)"
alias man='batman'
elif command -v bat >/dev/null; then
export MANPAGER='sed -u -e "s/[[0-9;]*m//g; s///g" | col -bx | bat -p -lman'
fi
if command -v chezmoi >/dev/null; then
# Since chezmoi doesn't support command alias yet:
# alias ch='chezmoi'
alias ch-h='echo "ch $@ maps: s-status a-add r-re-add "'
ch() {
if [ $# -eq 0 ]; then
chezmoi
return $?
fi
local cmd="$1"
shift
case "$cmd" in
s) cmd="status";;
e) cmd="edit";;
a) cmd="add";;
r) cmd="re-add";;
f) cmd="forget";;
d) cmd="diff";;
l) cmd="list";;
m) cmd="managed";;
p) cmd="source-path";;
h)
cat <<-'EOF' # for now <<- in case of gg=G
ch overwites the first arg if it's one of these: chezmoi [arg] <remaining args>
s status
e edit
a add
r re-add
f forget
d diff
l list
m managed
p source-path
EOF
return $?
esac
command chezmoi "$cmd" "$@"
}
if command -v git >/dev/null; then
alias dot='git -C "$(chezmoi source-path)"'
alias dots='git -C "$(chezmoi source-path)" status'
alias dotl='git -C "$(chezmoi source-path)" lg' # log + format
fi
fi
if [ -d "${HOME}/dev" ]; then
alias cdd='cd "${HOME}/dev"'
if [ -d "${HOME}/dev/tmp" ]; then
alias cdt='cd "${HOME}/dev/tmp"'
fi
fi
if command -v tmux >/dev/null; then
# Add shortcuts for
# tm dir
# tm arg1 arg2 [args...]
tm() {
if [ $# -eq 1 ]; then
tmux new -c "$1"
else
tmux "$@"
fi
}
fi
if command -v fx >/dev/null; then
export FX_NO_MOUSE=
fi
#
# Local settings to load late (not tracked in dotfiles).
#
if [ -f "${HOME}/.bashrc_local_late" ]; then
. "${HOME}/.bashrc_local_late"
fi
#
# Must come after sourcing scripts to prevent braking dependencies on common
# programs.
#
if command -v 'batgrep' >/dev/null; then
alias grep='batgrep'
fi
if command -v 'batdiff' >/dev/null; then
alias diff='batdiff'
fi