blob: 7500df6cb0ef95c4ca64ba31049e2dd996657023 (
plain)
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
# sh/ksh initialization
[ -f $HOME/.kshrc.private ] && . $HOME/.kshrc.private
#############################################################################
# ALIASES
#############################################################################
if command -v colorls > /dev/null ; then
LS='colorls'
export CLICOLOR=1
else
LS='ls'
fi
if [[ $(uname -s) == "Linux" ]]; then
alias ls='ls --color=auto -h --file-type -s'
alias ll='ls -l'
alias rm='rm --preserve-root --one-file-system -I'
alias cps='sync ; cvs up ; sync'
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
bind -m '^L'=clear'^J'
elif [[ $(uname -s) == "OpenBSD" ]]; then
alias ls='$LS'
alias ll='$LS -Flho'
alias cps='sync ; opencvs up ; sync'
bind '^L'=clear-screen
# Enable SIGINFO with ^T
stty status ^T
elif [[ $(uname -s) == "Darwin" ]]; then
alias ls='$LS -G'
alias ll='$LS -GFlho'
bind '^L'=clear-screen
export MACPATH=/opt/homebrew/bin/:/opt/homebrew/sbin
elif [[ $(uname -s) == "FreeBSD" ]]; then
alias ls='$LS -G'
alias ll='$LS -GFlho'
bind '^L'=clear-screen
# Enable SIGINFO with ^T
stty status ^T
export TERM=xterm-256color
fi
if [[ $HIGHDPI -eq 1 ]]; then
alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+1430+300 --sub-scale=0.5'
else
alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+950+200 --sub-scale=0.7'
fi
alias .2='cds ../..'
alias .3='cds ../../..'
alias .4='cds ../../../..'
alias j='jump'
alias c='cvs'
alias h='history -60 | sort -k2 | uniq -f2 | sort -bn'
alias sudo='sudo -H'
alias mc='mc --color'
alias pwgen='pwgen -s'
alias pkg_add='pkg_add -V'
alias dt='dtoggle'
alias tty-clock='tty-clock -s -c'
alias chromium='chromium --disk-cache-dir=/tmp'
alias open="xdg-open"
alias ffplay='ffplay -hide_banner'
alias gps='sync ; git pull ; sync'
alias cal='cal -m -w'
alias ed='ed -p*'
alias qw='pkill -9 xidle'
alias cc='cc -fdiagnostics-color'
alias weather='curl http://wttr.in/Karlsruhe'
alias dig='dig +noall +answer +comment'
alias gdb='gdb -q'
alias egdb='egdb -q'
#############################################################################
# FUNCTIONS
#############################################################################
# Following three functions from "shell FU by Isaac Levy" presentation
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
# Quick n dirty hack to generate a RSA key and a X509 cert
gennewcert() {
[[ -z "$1" ]] && echo "No alias provided" && return
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
-keyout $1.key.pem -new -subj /CN=$1 -out $1.cert.pem \
-addext subjectAltName=DNS:$1
}
# Neat trick from https://github.com/lf94/peek-for-tmux/blob/master/README.md
p() {
tmux split-window -p 33 more $@ || exit;
}
g() {
if [ -d ".got" ]; then
got "$@"
else
git "$@"
fi
}
enablevideoconf() {
echo "[+] Enable video recording"
doas sysctl kern.video.record=1
echo "[+] Enable audio recording"
doas sysctl kern.audio.record=1
echo "[+] Set mic to mic2"
doas mixerctl record.adc-0:1_source=mic2
echo "[+] Adjust input level"
sndioctl input.level=0.25
}
disablevideoconf() {
echo "[+] Disable video recording"
doas sysctl kern.video.record=0
echo "[+] Disable audio recording"
doas sysctl kern.audio.record=0
}
# Connect to a vmm(4) VM which uses the "local interface" networking scheme
vmmssh() {
if [ -z "$1" ]; then
echo "Usage: vmmssh <name of the vmm VM> [user]"
echo ""
echo "If no user name is provided, root is used"
return
fi
local _user="${2:-root}"
local _id=$(vmctl show $1| tail -1 | awk '{ print $1}')
if [ "${_id}" = "ID" ]; then
echo "No VM named $1 found"
return
fi
ssh -o StrictHostKeyChecking=no -l ${_user} 100.64.${_id}.3
}
checklatestsnap() {
ftp -MVo- http://172.23.5.36/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
ftp -MVo- "$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)/BUILDINFO"
ftp -MVo- http://ftp.openbsd.org/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
}
lostandfoundcheck() {
for mp in $(mount -t ffs | cut -d ' ' -f 3); do
[[ -d ${mp}/lost+found ]] && echo "${mp}/lost+found exists"
done
}
kshrc() {
. $HOME/.kshrc
}
updatesrc() {
if [ ! -d "/var/git" ]; then
local _oldpwd="$PWD"
cd /usr/src && {
sync && git pull ; sync
}
cd /usr/ports && {
sync && git pull ; sync
}
cd "$_oldpwd"
else
local _oldpwd="$PWD"
cd /var/git/src.git && {
sync && got fetch; sync
}
cd /usr/src && {
sync && got up && sync
}
cd /var/git/ports.git && {
sync && got fetch; sync
}
cd /usr/ports && {
sync && got up && sync
}
cd "$_oldpwd"
fi
}
updatepkgs() {
local _option="" _args=$1
if [[ -n $(sysctl -n kern.version | cut -d ' ' -f2 | grep beta) ]]; then
_option="-D snap"
fi
sync && doas pkg_add -ui $_option $_args
sync
return
if [ ! -d /var/pkg_mirror ]; then
doas mkdir /var/pkg_mirror
fi
doas mount_nfs -s -a 4 -T -r 32768 -w 32768 -o noatime,ro,intr mx.xosc.net:/pkg /var/pkg_mirror
doas umount /var/pkg_mirror/
}
getbsdrd() {
local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
ftp -V -o /tmp/bsd.rd "$_mirror/bsd.rd" || return 1
ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
cd /tmp && signify -C -p "/etc/signify/openbsd-$(uname -r | tr -d '.')-base.pub" -x /tmp/SHA256.sig bsd.rd
}
getbsdvm() {
local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
ftp -V -o /tmp/bsd "$_mirror/bsd" || return 1
ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
cd /tmp && signify -C -p "/etc/signify/openbsd-$(uname -r | tr -d '.')-base.pub" -x /tmp/SHA256.sig bsd && doas mv /tmp/bsd /bsd.vm
}
openports() {
local _filter1='internet'
local _filter2='icmp|raw|<-|->'
if [ "$1" = "-4" ]; then
_filter2="internet6|${_filter2}"
elif [ "$1" = "-6" ]; then
_filter1="internet6"
fi
printf "%-10s %-13s %-5s %-5s %-9s %s\n" "USER" "COMMAND" "PID" "PROTO" "FAMILY" "LOCAL ADDRESS"
fstat | grep "${_filter1}" | grep -vE "${_filter2}" | awk '{ printf("%-10s %-13s %5s %-5s %-9s %s\n", $1,$2,$3,$7,$5,$9); }' | sort -u
}
psearch() {
local pt="/usr/ports"
[[ -z ${1} ]] && echo "Need a keyword to search for" && return
[[ ! -d ${pt} ]] && echo "Cannot find ports tree" && return
cd ${pt} && make search name=${1}
}
sshopen() {
# The following is only needed on WSL not on other OSes
[ -f "/proc/version" ] && grep -qE "(Microsoft|WSL)" /proc/version 2> /dev/null
if [ $? -eq 0 ]; then
/usr/bin/keychain -q --nogui $HOME/.ssh/id_ed25519
return
fi
# Find all public keys...
for i in $(find $HOME/.ssh/ -maxdepth 1 -name "*.pub"); do
# ... and strip the .pub suffix
_key=`echo $i | sed -e 's/\.pub//'`
command ssh-add $_key
done
}
cvspsdiff() {
[ -z "$1" ] && return
cvsps -q -s "$1" -g | cdiff
}
psg() {
ps aux | grep "$@" | grep -v "grep $@"
}
qrcodegen() {
# Idea from https://dataswamp.org/~solene/2021-03-25-computer-to-phone-text.html
xclip -o | qrencode -o - > ~/qrclip.png && sxiv -g 600x600 ~/qrclip.png && rm ~/qrclip.png
}
cds() {
test -z "$1" && cd $HOME && ls -lh && return
cd "$1" && ls -lah
}
pkg_search() {
pkglocate "$1" | cut -d ':' -f 1 | sort -u | fzf
}
mkcd() {
[[ -n $1 ]] || return 0
[[ -d $1 ]] || mkdir -p "$1"
[[ -d $1 ]] && builtin cd "$1"
}
cget() {
curl -OL --compressed "$@"
}
showwifi() {
ifconfig | grep ieee | awk {'print $3'}
}
# Show infos about my external IP address
showmyipaddress() {
echo "My external IPv4 : $(ftp -4 -M -o - http://icanhazip.com 2> /dev/null)"
echo "My external IPv6 : $(ftp -6 -M -o - http://icanhazip.com 2> /dev/null)"
echo "My external PTR : $(ftp -M -o - http://icanhazptr.com 2> /dev/null)"
}
calc() {
echo "scale=3;$@" | bc -l
}
# Copied from https://github.com/agkozak/polyglot/ MIT license
_polyglot_branch_status() {
POLYGLOT_REF="$(env git symbolic-ref --quiet HEAD 2> /dev/null)"
case $? in # See what the exit code is.
0) ;; # $POLYGLOT_REF contains the name of a checked-out branch.
128) return ;; # No Git repository here.
# Otherwise, see if HEAD is in a detached state.
*) POLYGLOT_REF="$(env git rev-parse --short HEAD 2> /dev/null)" || return ;;
esac
if [ -n "$POLYGLOT_REF" ]; then
if [ "${POLYGLOT_SHOW_UNTRACKED:-1}" -eq 0 ]; then
POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status -uno 2>&1)
else
POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status 2>&1)
fi
POLYGLOT_SYMBOLS=''
case $POLYGLOT_GIT_STATUS in
*' have diverged,'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&*" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'Your branch is behind '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'Your branch is ahead of '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}*" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'new file: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}+" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'deleted: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}x" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'modified: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}!!" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'renamed: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}->" ;;
esac
case $POLYGLOT_GIT_STATUS in
*'Untracked files:'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}?" ;;
esac
[ -n "$POLYGLOT_SYMBOLS" ] && POLYGLOT_SYMBOLS=" $POLYGLOT_SYMBOLS"
printf ' (%s%s)' "${POLYGLOT_REF#refs/heads/}" "$POLYGLOT_SYMBOLS"
fi
unset POLYGLOT_REF POLYGLOT_GIT_STATUS POLYGLOT_SYMBOLS
}
lpf() {
local _pf=${1:-/etc/pf.conf}
doas pfctl -n -f ${_pf} && doas pfctl -F rules && doas pfctl -f ${_pf}
}
# Disable history logging for this shell
nohistory() {
HISTFILE=/dev/null
}
tog() {
TOG_COLORS=1 TERM=xterm /usr/local/bin/tog "$@"
}
# http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
jump() {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
mark() {
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
}
unmark() {
rm -i "$MARKPATH/$1"
}
marks() {
ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
}
#############################################################################
# COMPLETIONS
#############################################################################
# Mostly copied from
# https://github.com/qbit/dotfiles/blob/master/common/dot_ksh_completions
if [ -d ~/.password-store ]; then
PASS_LIST=$(
cd ~/.password-store
find . -type f -name \*.gpg | sed 's/^\.\///' | sed 's/\.gpg$//g'
)
set -A complete_tpm_1 -- $PASS_LIST usage
set -A complete_tpm_2 -- $PASS_LIST edit insert show rm
fi
set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)
if [ -d /var/db/pkg ]; then
PKG_LIST=$(/bin/ls -1 /var/db/pkg)
set -A complete_pkg_info -- $PKG_LIST
alias dpkgdel="doas pkg_delete"
set -A complete_dpkgdel_1 -- $PKG_LIST
fi
# relayctl completion. Second level only for 'show'
set -A complete_relayctl_1 -- monitor show load poll reload stop redirect table host log
set -A complete_relayctl_2 -- summary hosts redirects relays routers sessions
set -A complete_unwindctl_1 -- reload log status
if [ -d /etc/rc.d ]; then
RCD_LIST=$(/bin/ls /etc/rc.d)
set -A complete_rcctl_1 -- get getdef set check reload restart stop start disable enable order ls
set -A complete_rcctl_2 -- $RCD_LIST
alias drcctl="doas rcctl"
set -A complete_drcctl_1 -- get getdef set check reload restart stop start disable enable order ls
set -A complete_drcctl_2 -- $RCD_LIST
fi
set -A complete_tarsnap_1 -- --list-archives --print-stats --fsck --fsck-prune --nuke --verify-config --version --checkpoint-bytes --configfile --dry-run --exclude --humanize-numbers --keyfile --totals
set -A complete_got_1 -- $(got -h 2>&1 | sed -n s/commands://p)
# /tmp/.man-list is generated upon boot by /etc/rc.local with
# find /usr/share/man/ -type f | sed -e 's/.*\///' -e 's/\.[0-9]//' | sort -u
[[ -f /tmp/.man-list ]] && set -A complete_man -- $(cat /tmp/.man-list)
[[ -d $HOME/.marks ]] && set -A complete_j -- $(/bin/ls $HOME/.marks)
#############################################################################
# PROMPT
#############################################################################
_error_code() {
local _temp=$?
if [ $_temp -ne 0 ]; then
echo -n "\033[38;5;1m [$_temp]\033[m"
fi
}
if [ -z "$SSH_CLIENT" ]; then
PS1_TRENNER="!!"
else
PS1_TRENNER="@"
fi
if [[ $(id -u) -eq 0 ]]; then
PS1='\h$PS1_TRENNER\\033[0;101m\u\\033[0m \w [$?]\n\$ '
elif [[ $(whoami) = "xhr" ]] || [[ $(whoami) = "matthiaschmidt" ]]; then
PS1='\h \w$(_polyglot_branch_status)$(_error_code) \033[38;5;11m\$\033[m '
else
PS1='\h$PS1_TRENNER\u \w$(_polyglot_branch_status) [$?]\n\$ '
fi
#############################################################################
# MISC SETTINGS
#############################################################################
set bell-style none
#############################################################################
# VARIABLES
#############################################################################
[ -d $HOME/.keychain ] && . $HOME/.keychain/LWKA-6Q7VRN2-sh
LSCOLORS=Dxfxcxdxbxegedabagacad
HISTSIZE=30000
HISTFILE=$HOME/.sh_history
HISTCONTROL=ignoredups:ignorespace
BLOCKSIZE=M
PATH=$HOME/Documents/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:$MACPATH
LESSSECURE=1
PAGER='less -JWAceX'
LESS='-Xa'
PKG_PATH=http://172.23.5.36/pub/OpenBSD/%c/packages/%a:http://ftp.hostserver.de/pub/OpenBSD/%c/packages/%a
# better two-finger touchpad scrolling
export MOZ_USE_XINPUT2=1
# opengl acceleration
export MOZ_ACCELERATED=1
# force webrender to enable
export MOZ_WEBRENDER=1
export PATH HOME TERM LSCOLORS HISTSIZE BLOCKSIZE PAGER LESSSECURE PKG_PATH FETCH_CMD
|