summary refs log tree commit diff
path: root/.bashrc
blob: 8d19db88ca9f0a083b76483f50119d4c7cafa350 (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
# /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 !

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

# enable direnv
eval "$(direnv hook bash)"
# enable navi
eval "$(navi widget bash)"
# enable z.lua
if [ -d /usr/libexec/z_lua ]; then
	eval "$(luajit /usr/libexec/z_lua/z.lua --init bash enhanced once fzf)"
	# safe_load /usr/libexec/z_lua/czmod/czmod.bash
fi
# enable starship
eval "$(starship init bash)"

# Use keychain to reuse the ssh-agent and gpg-agent between logins
keychain --agents ssh,gpg -q id_rsa # AF6AB8C8B10436B9F61293632143BD2AAB94BCC4
safe_load "$HOME/.keychain/$(hostname)-sh"
safe_load "$HOME/.keychain/$(hostname)-sh-gpg"

# Set prompt
# export PS1="$(prompt)"
# if ! [[ "${PROMPT_COMMAND:-}" =~ _prompt_hook ]]; then
# 	PROMPT_COMMAND="_prompt_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
# fi
# _prompt_hook() {
# 	if [ "$?" != 0 ]; then
# 		PS1=$(prompt err)
# 	else
# 		PS1=$(prompt)
# 	fi
# }

# OSC7 escapte sequence
# https://codeberg.org/dnkl/foot/wiki#user-content-how-to-configure-my-shell-to-emit-the-osc-7-escape-sequence
_urlencode() {
	local length="${#1}"
	for ((i = 0; i < length; i++)); do
		local c="${1:$i:1}"
		case $c in
		%) printf '%%%02X' "'$c" ;;
		*) printf "%s" "$c" ;;
		esac
	done
}
_osc7_cwd() {
	printf '\e]7;file://%s%s\e\\' "$HOSTNAME" "$(_urlencode "$PWD")"
}
PROMPT_COMMAND+=";_osc7_cwd"

# Alias shell commands
# alias logout='dbus-send --session --type=method_call --print-reply --dest='
alias vim=nvim
alias v=nvim
alias nv=nvim
alias g=git
alias l='exa --long --classify --group --header --group-directories-first'
alias lt='exa --classify --group-directories-first -T'
alias ..='cd ..'
alias grep='grep --color=auto'
alias cat=bat
alias ssh='TERM=xterm-256color ssh'
alias balssh='ssh -p 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes'
alias balscp='scp -P 22222 -o User=root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o Compression=yes'
alias k=kubectl
alias org='nvim +Orgmode'
alias suspend=loginctl\ suspend
alias fm=vifm
alias rsy=rsyncez
alias rm=saferm
alias wlc=wl-copy
alias wlp=wl-paste
alias tt=timetrace
alias srv='rclone serve http --addr=localhost:8080 .'

alias daos=doas
alias dao=doas
alias daso=doas
alias dosa=doas