-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbashrc.kmarc
More file actions
223 lines (194 loc) · 6.08 KB
/
bashrc.kmarc
File metadata and controls
223 lines (194 loc) · 6.08 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
#!/usr/bin/env bash
# shellcheck disable=SC2016,SC1090,SC2155
####################
# Initialization #
####################
# Unset any funny command that would be executed before the prompt is shown
unset PROMPT_COMMAND
# Set a fallback terminal if there is no infocmp entry. This helps on older
# systems with no alacritty
if ! infocmp "$TERM" >/dev/null 2>&1; then
export TERM=xterm-256color
fi
###########################
# Environment variables #
###########################
set -a # export all declared variables
for _c in "$HOME"/.config/environment.d/*.conf; do
source "$_c"
done
unset _c
set +a
#############################
# Host-specific overrides #
#############################
# Supposedly a link to .pdotfiles/.../bashrc
if [ -f "$HOME"/.bashrc.local ]; then
# shellcheck disable=SC1091
source "$HOME"/.bashrc.local
fi
###################################
# Autostart graphical interface #
###################################
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
# https://wiki.archlinux.org/title/KDE
exec /usr/lib/plasma-dbus-run-session-if-needed startplasma-wayland
fi
# Only continue if this is an interactive shell
if ! [[ $- = *i* ]]; then
return 0
fi
###########################
# Functions and aliases #
###########################
alias ls="ls --color --group-directories-first"
alias diff='diff --color=auto'
alias grep='grep --color=auto'
alias mutt='neomutt'
alias teams-up='systemctl --user set-property teams.slice CPUQuota=$(( `nproc` * 100 ))% MemoryMax=4G'
alias teams-down='systemctl --user set-property teams.slice CPUQuota=$(( (`nproc` / 2) * 100 ))% MemoryMax=2.5G'
function git-recursive-pull() {
find . -type d -path '*/.git' -prune -printf "%h\n" \
| xargs -n1 -P4 bash -c \
'cd $1; if ! git pull --all &>/dev/null; then echo "ERROR: $1"; else echo "SUCCESS: $1"; fi' --
}
function git-worktree() {
if [ ${#*} -lt 2 ]; then
2>&1 echo "Usage: git-worktree JIRA-NNN short-name"
return 1
fi
local ticket orig_branch new_branch
ticket="$1"
new_branch=$2
orig_branch="$(git rev-parse --abbrev-ref HEAD)"
new_dir=../"$(basename "$PWD")"-"$new_branch"
git fetch origin "$orig_branch"
git worktree add "$new_dir" -B "$USER/$ticket-$new_branch"
if [ -f .envrc ]; then
cp .envrc "$new_dir/.envrc"
direnv allow "$new_dir"
fi
if [ -f user.bazelrc ]; then
cp user.bazelrc "$new_dir/user.bazelrc"
fi
}
if type -p mvn >/dev/null; then
_mvn_run() {
echo mvn "$@"
mvn "$@"
echo mvn "$@"
}
alias mci='_mvn_run clean install'
alias mcin='_mvn_run clean install -DskipTest'
alias mjacoco='_mvn_run jacoco:report'
alias mjavadoc='_mvn_run javadoc:aggregate'
alias me='_mvn_run exec:java'
alias mcie='_mvn_run clean install exec:java'
alias med='MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 mvn exec:java'
complete -o default -o nospace -F _mvn mci mcis mjacoco mjavadoc me mcie
fi
function cheat() {
curl --max-time 10 "http://cheat.sh/$1?style=stata-light"
}
function osc-copy() {
base64 | tr -d '\n' | awk '{printf "\033]52;c;%s\007", $0}' >/dev/tty
}
if type -p bazelisk >/dev/null; then
alias bqob='bazelisk query --output=build '
alias bqol='bazelisk query --output=label_kind '
complete -o nospace -F _bazel__complete bqob
fi
##########
# tmux #
##########
if type -p tmux &>/dev/null; then
alias tmux-session="tmux attach -t Session || tmux new -s Session"
function ssh-tmux() { ssh "$1" -t 'tmux attach'; }
if [ -n "$TMUX" ]; then
# shellcheck disable=SC2034
PANE_ID=$(tmux display-message -p '#P')
fi
fi
#########
# fzf #
#########
if type -p fzf &>/dev/null; then
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --border"
FZF_DEFAULT_COMMAND="rg --files --hidden --follow --glob '!{.git,.svn,node_modules}'"
# FZF keybindings are only sourced after the first bash-completion is used
if [ -f "$XDG_DATA_HOME/bash-completion/completions/fzf" ]; then
source "$XDG_DATA_HOME/bash-completion/completions/fzf"
fi
# Arch fzf package doesn't register the completion and key-bingings scripts
if [ -f /usr/share/fzf/completion.bash ]; then
source /usr/share/fzf/completion.bash
fi
if [ -f /usr/share/fzf/key-bindings.bash ]; then
source /usr/share/fzf/key-bindings.bash
fi
# # ALT-O opens selected file with xdg-open
# function __fzf_open__() {
# local cmd file
# cmd="${FZF_ALT_O_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
# -o -type f -print 2> /dev/null | sed 1d | cut -b3-"}"
# file=$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_O_OPTS") && printf '/usr/bin/xdg-open %q/%q' "$PWD" "$file"
# }
# # bind \M-o to __fzf_open__()
# if [[ ! -o vi ]]; then
# # ALT-O - open file
# bind '"\eo": " \C-e\C-u`__fzf_open__`\e\C-e\er\C-m"'
# else
# # ALT-O - open file
# bind '"\eo": "\C-x\C-addi`__fzf_open__`\C-x\C-e\C-x\C-r\C-m"'
# bind -m vi-command '"\eo": "ddi`__fzf_open__`\C-x\C-e\C-x\C-r\C-m"'
# fi
# fzf-git.sh installed via submodule
source "$HOME"/.local/opt/fzf-git/fzf-git.sh
fi
#############
# kubectl #
#############
if type -p kubectl >/dev/null; then
alias k=kubectl
fi
###############
# kubecolor #
###############
if type -p kubecolor >/dev/null; then
alias k=kubecolor
fi
#########
# grc #
#########
if type -p grc >/dev/null; then
if [[ -s "/etc/profile.d/grc.sh" ]]; then
GRC_ALIASES=true
source /etc/profile.d/grc.sh
# This alias enables colorized pipe (to less, etc)
alias colourify='grc -s --colour=on'
fi
fi
############
# direnv #
############
if type -p direnv &>/dev/null && ! type -t _direnv_hook &>/dev/null; then
eval "$(direnv hook bash)"
fi
##################
# liquidprompt #
##################
if type -p liquidprompt &>/dev/null; then
# Enable liquidprompt only in interactive and non-mc shells
if [[ -z "$MC_SID" && $- = *i* ]]; then
source "$(type -p liquidprompt)"
fi
fi
#########
# nvm #
#########
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
source "$NVM_DIR/bash_completion"
fi