-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
executable file
·314 lines (257 loc) · 8.74 KB
/
.bashrc
File metadata and controls
executable file
·314 lines (257 loc) · 8.74 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
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
#
# Smarter completion
#
# Perform file completion in a case insensitive fashion
bind "set completion-ignore-case on"
# Treat hyphens and underscores as equivalent
bind "set completion-map-case on"
# Show all possible completions if not specific enough
bind 'set show-all-if-ambiguous on'
# Immediately add a trailing slash when autocompleting symlinks to directories
bind "set mark-symlinked-directories on"
# Prepend cd to directory names automatically
shopt -s autocd 2> /dev/null
# Correct spelling errors during tab-completion
shopt -s dirspell 2> /dev/null
# Correct spelling errors in arguments supplied to cd
shopt -s cdspell 2> /dev/null
#
# History options
#
# Append to the history file, don't overwrite it
shopt -s histappend
# Save multi-line commands as one command
shopt -s cmdhist
# For setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# Avoid duplicate entries and lines starting with space
HISTCONTROL="erasedups:ignoreboth"
# Don't record some commands
export HISTIGNORE="&:[ ]*:cd:ls:y:clear:bash:exit:history:reboot:\
btop:ptop:ff:sys:lg:y";
#
# Prompt
#
# Chroot name (if any)
[ -r /etc/debian_chroot ] && debian_chroot=$(< /etc/debian_chroot)
# Enable color if supported
case "$TERM" in
*-256color|alacritty|foot) color_prompt=yes ;;
esac
if [ "$color_prompt" = yes ]; then
# Default prompt
# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# # Timing code from https://stackoverflow.com/a/34812608
# timer_now() {
# date +%s%N
# }
# Dynamic prompt function
set_prompt() {
# local timer_show=""
# if [[ -n "$timer_start" ]]; then
# local now=$(timer_now)
# local delta_us=$(( (now - timer_start) / 1000 ))
# local us=$((delta_us % 1000))
# local ms=$(((delta_us / 1000) % 1000))
# local s=$(((delta_us / 1000000) % 60))
# local m=$(((delta_us / 60000000) % 60))
# local h=$((delta_us / 3600000000))
# if ((h > 0)); then timer_show=${h}h${m}m
# elif ((m > 0)); then timer_show=${m}m${s}s
# elif ((s >= 10)); then timer_show=${s}.$((ms / 100))s
# elif ((s > 0)); then timer_show=${s}.$(printf %03d $ms)s
# elif ((ms >= 100)); then timer_show=${ms}ms
# elif ((ms > 0)); then timer_show=${ms}.$((us / 100))ms
# else timer_show=${us}us
# fi
# fi
# local last_exit=$__LAST_EXIT
local last_exit=$?
# # Regular text colors
# local BLACK='\[\e[0;30m\]'
local RED='\[\e[0;31m\]'
# local GREEN='\[\e[0;32m\]'
# local YELLOW='\[\e[0;33m\]'
# local BLUE='\[\e[0;34m\]'
# local MAGENTA='\[\e[0;35m\]'
# local CYAN='\[\e[0;36m\]'
local WHITE='\[\e[0;37m\]'
# Bold text colors
# local BBLACK='\[\e[1;30m\]'
local BRED='\[\e[1;31m\]'
local BGREEN='\[\e[1;32m\]'
local BYELLOW='\[\e[1;33m\]'
local BBLUE='\[\e[1;34m\]'
local BMAGENTA='\[\e[1;35m\]'
local BCYAN='\[\e[1;36m\]'
# local BWHITE='\[\e[1;37m\]'
# # Background colors
# local BGBLACK='\[\e[40m\]'
# local BGRED='\[\e[41m\]'
# local BGGREEN='\[\e[42m\]'
# local BGYELLOW='\[\e[43m\]'
# local BGBLUE='\[\e[44m\]'
# local BGMAGENTA='\[\e[45m\]'
# local BGCYAN='\[\e[46m\]'
# local BGWHITE='\[\e[47m\]'
local CHROOT='${debian_chroot:+'"$BMAGENTA"'($debian_chroot) '"$WHITE"'}'
local NIX=""
if [[ -n "$IN_NIX_SHELL" ]]; then
NIX="$BBLUE(nix-shell)$WHITE "
fi
local CONDA=""
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
CONDA="$BRED($CONDA_DEFAULT_ENV) $WHITE"
fi
local VENV=""
if [[ -n "$VIRTUAL_ENV_PROMPT" ]]; then
# Strip whitespace
local v="${VIRTUAL_ENV_PROMPT//[[:space:]]/}"
# Add parentheses if missing
if [[ "$v" != \(*\) ]]; then
v="($v)"
fi
# Formatted like "(venv_name) "
VENV="$BMAGENTA$v "
fi
local USER="$BGREEN\u"
local AT="$BMAGENTA@"
local HOST="$BCYAN\h$WHITE"
local DIRECTORY="$BYELLOW\w"
# Red # for root
# Red $ on failed command
# White $ otherwise
local symbol
if [ "$UID" -eq 0 ]; then
symbol="$RED#$WHITE "
elif [ "$last_exit" -eq 0 ]; then
symbol="$WHITE\$ "
else
symbol="$RED\$ $WHITE"
fi
PS1="$CHROOT$NIX$CONDA$VENV$USER$AT$HOST:$DIRECTORY$symbol"
# PS1="($timer_show) $VENV$CHROOT$USER$HOST:$DIRECTORY$symbol"
}
# trap 'timer_start=$(timer_now)' DEBUG
# PROMPT_COMMAND='__LAST_EXIT=$?; set_prompt'
PROMPT_COMMAND='set_prompt'
else
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
fi
unset color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
;;
*)
;;
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 dir='dir --color=auto'
#alias vdir='vdir --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'
# Alias definitions.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# 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
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
#
# Enable CLI tools enhancements
#
# Show a warning only in interactive shells
_warn_missing() {
[[ $- == *i* ]] && printf 'Warning: %s not found; skipping %s\n' "$1" "$2" >&2
}
# Enable fzf
if command -v fzf >/dev/null 2>&1; then
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
else
_warn_missing fzf "fzf initialization"
fi
# Enable zoxide and replace cd (can also use cdi to search cd history)
if command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init bash --cmd cd)"
else
_warn_missing zoxide $'zoxide initialization\n\tInstall through package manager or with: curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh'
fi
# Enable batman (colored man pages)
if command -v batman >/dev/null 2>&1; then
eval "$(batman --export-env)"
else
_warn_missing batman "batman initialization"
fi
# Enable batpipe (colored less)
if command -v batpipe >/dev/null 2>&1; then
eval "$(batpipe)"
else
_warn_missing batpipe "batpipe initialization"
fi
# Enable atuin for better bash history (atuin needs bash-preexec)
if command -v atuin >/dev/null 2>&1; then
if [[ -f ~/.bash-preexec.sh ]]; then
source ~/.bash-preexec.sh
eval "$(atuin init bash)"
else
_warn_missing ~/.bash-preexec.sh $'atuin initialization\n\tInstall with: curl -fsSL https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh'
fi
else
_warn_missing atuin $'atuin initialization\n\tInstall through package manager or with: curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh'
fi
# Direnv integration
if command -v direnv >/dev/null 2>&1; then
eval "$(direnv hook bash)"
else
_warn_missing direnv "direnv initialization"
fi
# Use yazi shell wrapper to enable changing cwd from yazi
if command -v yazi >/dev/null 2>&1; then
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
command yazi "$@" --cwd-file="$tmp"
IFS= read -r -d '' cwd < "$tmp"
[ "$cwd" != "$PWD" ] && [ -d "$cwd" ] && builtin cd -- "$cwd"
rm -f -- "$tmp"
}
else
_warn_missing yazi "yazi shell wrapper function"
fi
unset -f _warn_missing
# Set Zed as default editor
export EDITOR="zeditor"
export VISUAL="zeditor"
export SUDO_EDITOR="zeditor --wait" # (sudoedit)
export GIT_EDITOR="zeditor --wait"