summary refs log tree commit diff
path: root/.bashrc
blob: 8979f1d19bc32f367b548f59b3a482760b36e099 (plain) (blame)
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
# vim: ft=bash
# /etc/skel/.bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.  So make sure this doesn't display
# anything or bad things will happen !

function safe_load() {
	sh="$1"
	[ -r "$sh" ] && . "$sh"
	unset sh
}

# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]]; then
	# Shell is non-interactive.  Be done now!
	return
fi

# enable bash vi mode
set -o vi
bind -m vi-insert -x '"\C-l": clear'

# Append to history file
shopt -s histappend
#HISTSIZE=50000
#HISTFILESIZE=500000
HISTCONTROL=ignorespace

declare -a _userfuncs

# OSC7 escapte sequence
# https://codeberg.org/dnkl/foot/wiki#spawning-new-terminal-instances-in-the-current-working-directory
function _osc7_cwd() {
	local strlen=${#PWD}
	local encoded=""
	local pos c o
	for ((pos = 0; pos < strlen; pos++)); do
		c=${PWD:$pos:1}
		case "$c" in
		[-/:_.!\'\(\)~[:alnum:]]) o="${c}" ;;
		*) printf -v o '%%%02X' "'${c}" ;;
		esac
		encoded+="${o}"
	done
	printf '\e]7;file://%s%s\e\\' "${HOSTNAME}" "${encoded}"
}
_userfuncs+=(_osc7_cwd)

# OSC133 command prompt marker
# https://codeberg.org/dnkl/foot/wiki#jumping-between-prompts
function _osc133_prompt_marker() {
	printf '\e]133;A\e\\'
}
_userfuncs+=(_osc133_prompt_marker)

# set window title
function _osc0_set_win_title() {
	printf '\033]0;%s\007' "${PWD} (${HOSTNAME}) - ${TERM}"
}
_userfuncs+=(_osc0_set_win_title)

# append to HISTFILE on every prompt
function _histappend() {
	builtin history -a
}
_userfuncs+=(_histappend)

# assign precmds to the precmds array above this line!
function _userfuncs_exec() {
	IFS=';'
	eval "${_userfuncs[*]}"
}

# TODO: when using starship we need to use it's precmd helpers to avoid
# breaking the status module
if [ -x "$(command -v starship)" ]; then
	starship_precmd_user_func="_userfuncs_exec"
else
	[[ ${PROMPT_COMMAND:=} != *_userfuncs_exec* ]] &&
		PROMPT_COMMAND="_userfuncs_exec;${PROMPT_COMMAND#;}"
fi

# Alias shell commands
# alias logout="dbus-send --session --type=method_call --print-reply --dest="
alias ..="cd .."
alias balscp="scp -P 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes"
alias balssh="ssh -p 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes"
alias c=clifm
alias cat=bat
alias clear='printf "\033[H\033[2J"'
alias dao=doas
alias daos=doas
alias daso=doas
alias dbx=distrobox
alias diffconfig='doas /usr/src/linux/scripts/diffconfig'
alias dosa=doas
alias droidcam-cli="doas modprobe v4l2loopback && doas droidcam-cli"
alias f=fzfez
alias fm="swallow /home/robert/src/fm/target/release/fm"
alias g=git
alias grep="grep --color=auto"
alias k=kubectl
alias l="eza --long --classify --inode --group --header --group-directories-first --time-style=long-iso --git"
alias lt="eza --classify --group-directories-first --git -T"
alias mk=make
alias ni=ninja
alias nv=nvim
alias open="xdg-open"
alias org="nvim +Orgmode"
alias pandoc="pandoc -d \${HOME}/.config/pandoc.yml"
alias py=python
alias rip='trash-put'
alias rm='rm -i'
alias rsy=rsyncez
alias srv="rclone serve http --addr=0.0.0.0:8080"
alias ssh="TERM=xterm-256color ssh"
alias suspend=loginctl\ suspend
alias tt=timew
alias tw=timew
alias v=nvim
alias vi=nvim
alias vim=nvim
alias wlc=wl-copy
alias wlp=wl-paste
alias mpa="mpv --no-video"
alias zb="zig build"

export BAT_THEME=base16-256
# export DOCKER_BUILDKIT=1
export DOCKER=podman
export ENTER_DRIVER=$DOCKER
# set default editor
export EDITOR=nvim
export VISUAL=$EDITOR
# configure gpg-agent
export GPG_TTY=$(tty)
# Set less default options
export LESS='--hilite-search --hilite-unread --long-prompt --raw-control-chars --chop-long-lines --quit-if-one-screen --no-init'
export PAGER='ov'
export MANPAGER='ov'
# export PAGER='page -WC -q 90000 -z 90000'
# export MANPAGER='page -t man'

# Set the rsync ssh command to use by default
export RSYNC_RSH='ssh -T -x -o Compression=no'
# Use the new build backend in docker
# zettelkasten
export ZK_NOTEBOOK_DIR=${HOME}/zettelkasten
export ZK_JOURNAL_DIR=500_journals

# enable direnv
[ -x "$(command -v direnv)" ] && eval "$(direnv hook bash)"

# enable todo
[ -x "$(command -v todo)" ] && eval "$(todo hook bash)"

# enable starship
# NOTE: eval this last, to avoid losing PROMPT_COMMAND
[ -x "$(command -v starship)" ] && eval "$(starship init bash)"

# Use keychain to reuse the ssh-agent and gpg-agent between logins
# [ -x "$(command -v keychain)" ] && eval "$(keychain --eval --agents ssh,gpg -q id_ed25519)" # AF6AB8C8B10436B9F61293632143BD2AAB94BCC4
# safe_load "$HOME/.keychain/$(hostname)-sh"
# safe_load "$HOME/.keychain/$(hostname)-sh-gpg"

# enable fzf ctrl-r
# exit ctrl-r early
export FZF_DEFAULT_OPTS="--bind=shift-tab:replace-query"
export FZF_CTRL_R_OPTS="--layout=reverse --bind=ctrl-space:print-query"
# predefine compgen helpers using ripgrep and fd
_fzf_compgen_path() { rg --files --glob "!.git" . "$1"; }
_fzf_compgen_dir() { fd --type d --hidden --follow --exclude ".git" . "$1"; }
# register completions for some additional commands
safe_load /usr/share/fzf/key-bindings.bash
safe_load /usr/share/bash-completion/completions/fzf

## populate PATH
. /etc/profile.d/path_func.sh

[ -d "${HOME}/bin/$(uname -n)" ] && pathprepend "${HOME}/bin/$(uname -n)"
[ -d "${HOME}/zettelkasten/bin" ] && pathappend "${HOME}/zettelkasten/bin"

export GOPATH="${HOME}/go"
if [ -d "${GOPATH}" ]; then
	pathappend "${GOPATH}/bin"
fi

if [ -d "${HOME}/.cargo/bin" ]; then
	pathappend "${HOME}/.cargo/bin"
fi

# enable sccache globally
# export RUSTC_WRAPPER=/usr/bin/sccache
# export SCCACHE_DIR=/var/tmp/sccache
# export SCCACHE_MAX_FRAME_LENGTH=104857600

export SSH_ASKPASS=${HOME}/bin/askpass
export SSH_ASKPASS_REQUIRE=prefer

# enable zoxide
[ -x "$(command -v zoxide)" ] && eval "$(zoxide init bash)"

# enable broot
[ -x "$(command -v broot)" ] && source "${HOME}/.config/broot/launcher/bash/br"
source "$HOME/.cargo/env"