-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
208 lines (176 loc) · 4.38 KB
/
Copy pathbashrc
File metadata and controls
208 lines (176 loc) · 4.38 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
#!/bin/bash
PROMPT_COMMAND=()
# shellcheck disable=SC2034
DOTFILES="$(dirname -- "$(readlink -- "${BASH_SOURCE[0]:-"$0"}")")"
exists() {
command -v -- "$1" >/dev/null 2>&1
}
# options
shopt -s checkwinsize
shopt -s dotglob
shopt -s no_empty_cmd_completion
shopt -s globstar
shopt -s lithist
shopt -s nullglob
HISTCONTROL="ignoreboth"
HISTSIZE=100000
unset HISTFILE
# commands
args() {
printf "%s\n" "${@@Q}"
}
mkcd() {
# shellcheck disable=SC2164
mkdir -p -- "$1" && cd -- "$1"
}
bak() {
local target
for target in "$@"; do
mv -i -- "${target}" "${target}.bak"
done
}
unbak() {
local target
for target in "$@"; do
[[ "${target}" == *.bak ]] || continue
mv -i -- "${target}" "${target%.bak}"
done
}
rm() {
echo "bash: error: rm command is disabled. use \`rmv\` or \`remove\` instead." >&2
return 1
}
deno() {
local -x DENO_DIR="${HOME}/.deno/cache"
command deno "$@"
}
jq() {
local -x JQ_COLORS="2;39:0;31:0;31:0;36:0;32:1;39:1;39"
command jq "$@"
}
# aliases
if exists eza; then
alias ls='eza --classify --no-quotes --sort=Name'
alias la='eza --classify --no-quotes --sort=Name --all'
alias lA='eza --classify --no-quotes --sort=Name --all'
alias lt='eza --classify --no-quotes --sort=Name --all --tree'
alias ll='eza --classify --no-quotes --sort=Name --all --long --binary --group --time-style=long-iso'
alias llt='eza --classify --no-quotes --sort=Name --all --tree --long --binary --group --time-style=long-iso'
elif exists dircolors; then
alias ls='ls --classify --color=auto --quoting-style=literal'
alias la='ls --classify --color=auto --quoting-style=literal --almost-all'
alias lA='ls --classify --color=auto --quoting-style=literal --almost-all'
alias ll='ls --classify --color=auto --quoting-style=literal --almost-all --format=long --time-style=long-iso'
else
alias ls='ls -F'
alias la='ls -AF'
alias lA='ls -AF'
alias ll='ls -AFl'
fi
if exists dircolors; then
alias grep='grep -E --color=auto'
else
alias grep='grep -E'
fi
if exists bat; then
alias cat='bat'
fi
if exists rg; then
alias rga="rg --hidden --glob='!.git/'"
fi
if exists fend; then
alias calc='fend'
else
alias calc='bc -l'
fi
alias remove='command rm'
alias reload='exec -l "${BASH}"'
# key bindings
bind C-F:menu-complete
bind C-B:menu-complete-backward
# prompt
simple-prompt() {
# shellcheck disable=SC2206
PROMPT_COMMAND=( ${PROMPT_COMMAND[*]/__default_prompt} )
PS1='\[\e[0m\e[32m\]\u'
if [[ -v SSH_CONNECTION ]]; then
PS1+='\[\e[33m\]@\H'
fi
PS1+=' \[\e[34m\]\W \$\[\e[0m\] '
PS2='> '
}
__default_prompt() {
local status=$1
local -A COLOR=(
[default]='\[\e[0m\]'
[red]='\[\e[38;5;235;48;5;203m\]'
[orange]='\[\e[38;5;235;48;5;216m\]'
[yellow]='\[\e[38;5;235;48;5;227m\]'
[green]='\[\e[38;5;235;48;5;156m\]'
[cyan]='\[\e[38;5;235;48;5;117m\]'
[blue]='\[\e[38;5;235;48;5;111m\]'
[pink]='\[\e[38;5;235;48;5;170m\]'
[magenta]='\[\e[38;5;235;48;5;207m\]'
[gray]='\[\e[38;5;255;48;5;245m\]'
)
PS1="${COLOR[default]}"
if (( status != 0 )); then
PS1+="${COLOR[red]} ${status} "
fi
local njobs
njobs="$(jobs -p | wc -l)"
if (( njobs != 0 )); then
PS1+="${COLOR[orange]} ${njobs} "
fi
PS1+="${COLOR[magenta]}"' \s '
if (( EUID == 0 )); then
PS1+=$'\u2502 \u '
else
PS1+="${COLOR[green]}"' \u '
fi
if [[ -v SSH_CONNECTION ]]; then
PS1+="${COLOR[yellow]}"' \H '
fi
PS1+="${COLOR[gray]}"' \W '"${COLOR[default]}"
if [[ -v TMUX ]]; then
PS1+=$'\u00A0'
else
PS1+=' '
fi
local width
width="$(echo -n "${PS1@P}" | sed 's/\x01[^\x02]*\x02//g' | wc -L)"
printf -v PS2 "${COLOR[default]}${COLOR[gray]} %*s ${COLOR[default]} " $((width-3)) "..."
}
if [[ "$(tput colors 2>/dev/null)" -ge 256 ]]; then
PROMPT_COMMAND+=( __default_prompt )
else
simple-prompt
fi
# gpg-agent
if exists gpgconf; then
unset SSH_AGENT_PID
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
GPG_TTY="$(tty)"
export SSH_AUTH_SOCK GPG_TTY
__gpg_agent_updatestartuptty() {
( gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1 & )
}
PROMPT_COMMAND+=( __gpg_agent_updatestartuptty )
fi
# dircolors
if exists dircolors; then
if [[ -f ~/.config/dircolors ]]; then
eval "$(dircolors -b ~/.config/dircolors)"
elif [[ -f /etc/DIR_COLORS ]]; then
eval "$(dircolors -b /etc/DIR_COLORS)"
else
eval "$(dircolors -b)"
fi
fi
# environment variables
export LANG="en_US.UTF-8"
export EDITOR="vim"
export VISUAL="vim"
export PAGER="less"
export LESS="-FMRSgi -j.5 -z-4"
export LESSHISTFILE="-"