-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
273 lines (226 loc) · 6.72 KB
/
bashrc
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
#!/bin/bash
#
# Tacahiroy's bashrc
#
# Copyright © 2022 Takahiro Yoshihara <tacahiroy@gmail.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
umask 0022
# https://askubuntu.com/a/279014/579600
shell-colors() {
for x in {0..8}; do
for i in {30..37}; do
for a in {40..47}; do
echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "
done
echo
done
done
echo ""
}
shell-256-colors() {
for i in {0..255}; do
printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i"
if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
printf "\n"
fi
done
}
if [ -e "$HOME/.dircolors" ]; then
eval "$(dircolors "$HOME/.dircolors")"
fi
#--------------------
# Guard
#--------------------
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
if command -v ghq >/dev/null 2>&1; then
GIT_CMD=$(command -v ghq)
IS_PURE_GIT=no
else
GIT_CMD=$(command -v git)
IS_PURE_GIT=yes
fi
#---------------------
# Functions
#---------------------
_dot() {
f=$1
# shellcheck source=/dev/null
[ -s "${f}" ] && . "${f}"
}
update_plugins() {
while read -r a; do ghq get -u "${a}" >/dev/null 2>&1; done < "$HOME/.bash/plugins.txt"
}
git_clone() {
local url=$1
local dest=$2
if [ "${IS_PURE_GIT}" = yes ]; then
git clone "${url}" "${dest}"
else
ghq get "${url}"
fi
[ ! -x "$(command -v ghq)" ] && return
update_plugins
}
cdup() {
cd ..
}
## plugins
#
setup_plugins() {
if [ -z "${GIT_CMD}" ]; then
echo "Git was not found on your system."
return 1
fi
if [ -z "${GIT_ROOT}" ]; then
echo "GIT_ROOT is not set."
return 1
fi
if [ -f "$HOME/.bash/plugins.txt" ]; then
while read -r a; do
local _rn _init _repo
_rn=$(echo "${a}" | awk '{ print $1 }')
_init=$(echo "${a}" | awk '{ print $2 }')
_repo="${GIT_ROOT}/${_rn}"
if [ ! -d "$(readlink -f "${_repo}")" ]; then
git_clone "https://${_rn}" "${_repo}"
fi
PATH=$PATH:"${_repo}"
[ -z "${_init}" ] && continue
_dot "${_repo}/${_init}"
done < "$HOME/.bash/plugins.txt"
fi
}
setup_plugins
#--------------------
# Prompt
#--------------------
if [ -f "$HOME/.bash/prompt.sh" ]; then
git_status="${GIT_ROOT}/github.com/romkatv/gitstatus"
if [ -d "${git_status}" ]; then
# shellcheck source=/dev/null
. "${git_status}/gitstatus.prompt.sh"
extras='${GITSTATUS_PROMPT:+(${GITSTATUS_PROMPT})}'
fi
# shellcheck source=~/.bash/prompt.sh
. "$HOME/.bash/prompt.sh"
set_prompt "${BRIGHT_RED}" "${GREEN}" "${BLUE}" "${extras:-}"
fi
unset MAILCHECK
FIGNORE="${FIGNORE}:@tmp:retry:tfstate:backup"
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoreboth:erasedups
# append to the history file, don't overwrite it
shopt -s histappend
# automatic spell correction for cd
shopt -s cdspell
# After each command, append to the history file and reread it
# http://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=50000
HISTFILESIZE=${HISTSIZE}
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
case "${PLATFORM}" in
macos)
;;
*)
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar
;;
esac
if [ -f "$HOME/.bashrc.local" ]; then
# shellcheck source=~/.bashrc.local
. "$HOME/.bashrc.local"
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
..() {
if [ $# -eq 0 ]; then
cd ..
else
eval "cd $(printf \"%"$1"s\" | sed 's/ /..\//g')"
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
# shellcheck source=/dev/null
. /usr/share/bash-completion/bash_completion
fi
if [ -f /etc/bash_completion ]; then
# shellcheck source=/dev/null
. /etc/bash_completion
fi
fi
#--------------------
# Key bindings
#--------------------
bind '"\C-p":history-search-backward'
bind '"\C-n":history-search-forward'
bind '"\C-y"':"\"cdup\r\""
case "${PLATFORM}" in
# NOTE: the version of ssh is too new on Void Linux, which is 9.0p1, and it fails
# to retrieve an identity from older versions of ssh-agent.
wsl)
# https://github.com/rupor-github/wsl-ssh-agent/tree/5fe57762c#wsl-2-compatibility
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
if ! ss -a | grep -q "${SSH_AUTH_SOCK}"; then
rm -f "${SSH_AUTH_SOCK}"
( setsid socat UNIX-LISTEN:"${SSH_AUTH_SOCK}",fork,umask=007 EXEC:"$HOME/winhome/.wsl/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
fi
;;
macos|linux)
if ! pgrep ssh-agent >/dev/null; then
eval "$(ssh-agent)"
fi
;;
*)
;;
esac
if [ "${PLATFORM}" = wsl ] && [ -x "$HOME/bin/tmp-clean.sh" ]; then
bash "$HOME"/bin/tmp-clean.sh
fi
if [ -f "$HOME/.bashrc.local" ]; then
# shellcheck source=~/.bashrc.local
. "$HOME/.bashrc.local"
fi
if [ -n "${FILTER_CMD}" ]; then
# shellcheck source=/dev/null
[ -f "$HOME/.bash/selectors.sh" ] && . "$HOME/.bash/selectors.sh"
fi
# if [ -x "$(command -v starship)" ]; then
# export STARSHIP_CONFIG=$HOME/.config/starship/starship.toml
# eval "$(starship init bash)"
# fi
# Adding wsl-open as a browser for Bash for Windows
if [[ $(uname -r) =~ (m|M)icrosoft ]]; then
if [[ -z $BROWSER ]]; then
export BROWSER=wsl-open
else
export BROWSER=$BROWSER:wsl-open
fi
fi
if [ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
# shellcheck source=~/.sdkman/bin/sdkman-init.sh
. "$HOME/.sdkman/bin/sdkman-init.sh"
fi
# shellcheck source=~/.cargo/env
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
GPG_TTY=$(tty)
export GPG_TTY
gpgconf --launch gpg-agent