1 # sh/ksh initialization
3 [ -f $HOME/.kshrc.private ] && . $HOME/.kshrc.private
5 #############################################################################
7 #############################################################################
9 if command -v colorls > /dev/null ; then
16 if [[ $(uname -s) == "Linux" ]]; then
17 alias ls='ls --color=auto -h --file-type -s'
19 alias rm='rm --preserve-root --one-file-system -I'
20 alias cps='sync ; cvs up ; sync'
21 if [ -x /usr/bin/dircolors ]; then
22 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
24 bind -m '^L'=clear'^J'
25 elif [[ $(uname -s) == "OpenBSD" ]]; then
28 alias cps='sync ; opencvs up ; sync'
30 bind '^L'=clear-screen
32 # Enable SIGINFO with ^T
34 elif [[ $(uname -s) == "Darwin" ]]; then
38 bind '^L'=clear-screen
39 export MACPATH=/opt/homebrew/bin/:/opt/homebrew/sbin
40 elif [[ $(uname -s) == "FreeBSD" ]]; then
44 bind '^L'=clear-screen
46 # Enable SIGINFO with ^T
49 export TERM=xterm-256color
52 if [[ $HIGHDPI -eq 1 ]]; then
53 alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+1430+300 --sub-scale=0.5'
55 alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+950+200 --sub-scale=0.7'
59 alias .3='cds ../../..'
60 alias .4='cds ../../../..'
63 alias h='history -60 | sort -k2 | uniq -f2 | sort -bn'
66 alias pwgen='pwgen -s'
67 alias pkg_add='pkg_add -V'
69 alias tty-clock='tty-clock -s -c'
70 alias chromium='chromium --disk-cache-dir=/tmp'
72 alias ffplay='ffplay -hide_banner'
73 alias gps='sync ; git pull ; sync'
76 alias qw='pkill -9 xidle'
77 alias cc='cc -fdiagnostics-color'
78 alias weather='curl http://wttr.in/Karlsruhe'
79 alias dig='dig +noall +answer +comment'
83 #############################################################################
85 #############################################################################
87 # Following three functions from "shell FU by Isaac Levy" presentation
88 yell() { echo "$0: $*" >&2; }
89 die() { yell "$*"; exit 111; }
90 try() { "$@" || die "cannot $*"; }
92 # Quick n dirty hack to generate a RSA key and a X509 cert
94 [[ -z "$1" ]] && echo "No alias provided" && return
96 openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
97 -keyout $1.key.pem -new -subj /CN=$1 -out $1.cert.pem \
98 -addext subjectAltName=DNS:$1
101 # Neat trick from https://github.com/lf94/peek-for-tmux/blob/master/README.md
103 tmux split-window -p 33 more $@ || exit;
107 if [ -d ".got" ]; then
115 echo "[+] Enable video recording"
116 doas sysctl kern.video.record=1
117 echo "[+] Enable audio recording"
118 doas sysctl kern.audio.record=1
119 echo "[+] Set mic to mic2"
120 doas mixerctl record.adc-0:1_source=mic2
121 echo "[+] Adjust input level"
122 sndioctl input.level=0.25
126 echo "[+] Disable video recording"
127 doas sysctl kern.video.record=0
128 echo "[+] Disable audio recording"
129 doas sysctl kern.audio.record=0
132 # Connect to a vmm(4) VM which uses the "local interface" networking scheme
135 echo "Usage: vmmssh <name of the vmm VM> [user]"
137 echo "If no user name is provided, root is used"
141 local _user="${2:-root}"
142 local _id=$(vmctl show $1| tail -1 | awk '{ print $1}')
144 if [ "${_id}" = "ID" ]; then
145 echo "No VM named $1 found"
149 ssh -o StrictHostKeyChecking=no -l ${_user} 100.64.${_id}.3
153 ftp -MVo- http://172.23.5.36/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
154 ftp -MVo- "$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)/BUILDINFO"
155 ftp -MVo- http://ftp.openbsd.org/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
158 lostandfoundcheck() {
159 for mp in $(mount -t ffs | cut -d ' ' -f 3); do
160 [[ -d ${mp}/lost+found ]] && echo "${mp}/lost+found exists"
169 if [ ! -d "/var/git" ]; then
172 sync && git pull ; sync
175 sync && git pull ; sync
180 cd /var/git/src.git && {
181 sync && got fetch; sync
184 sync && got up && sync
186 cd /var/git/ports.git && {
187 sync && got fetch; sync
190 sync && got up && sync
197 local _option="" _args=$1
198 if [[ -n $(sysctl -n kern.version | cut -d ' ' -f2 | grep beta) ]]; then
202 sync && doas pkg_add -ui $_option $_args
207 if [ ! -d /var/pkg_mirror ]; then
208 doas mkdir /var/pkg_mirror
210 doas mount_nfs -s -a 4 -T -r 32768 -w 32768 -o noatime,ro,intr mx.xosc.net:/pkg /var/pkg_mirror
211 doas umount /var/pkg_mirror/
215 local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
217 ftp -V -o /tmp/bsd.rd "$_mirror/bsd.rd" || return 1
218 ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
220 cd /tmp && signify -C -p "/etc/signify/openbsd-$(uname -r | tr -d '.')-base.pub" -x /tmp/SHA256.sig bsd.rd
224 local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
226 ftp -V -o /tmp/bsd "$_mirror/bsd" || return 1
227 ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
229 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
233 local _filter1='internet'
234 local _filter2='icmp|raw|<-|->'
236 if [ "$1" = "-4" ]; then
237 _filter2="internet6|${_filter2}"
238 elif [ "$1" = "-6" ]; then
242 printf "%-10s %-13s %-5s %-5s %-9s %s\n" "USER" "COMMAND" "PID" "PROTO" "FAMILY" "LOCAL ADDRESS"
243 fstat | grep "${_filter1}" | grep -vE "${_filter2}" | awk '{ printf("%-10s %-13s %5s %-5s %-9s %s\n", $1,$2,$3,$7,$5,$9); }' | sort -u
247 local pt="/usr/ports"
249 [[ -z ${1} ]] && echo "Need a keyword to search for" && return
250 [[ ! -d ${pt} ]] && echo "Cannot find ports tree" && return
252 cd ${pt} && make search name=${1}
256 # The following is only needed on WSL not on other OSes
257 [ -f "/proc/version" ] && grep -qE "(Microsoft|WSL)" /proc/version 2> /dev/null
258 if [ $? -eq 0 ]; then
259 /usr/bin/keychain -q --nogui $HOME/.ssh/id_ed25519
263 # Find all public keys...
264 for i in $(find $HOME/.ssh/ -maxdepth 1 -name "*.pub"); do
265 # ... and strip the .pub suffix
266 _key=`echo $i | sed -e 's/\.pub//'`
267 command ssh-add $_key
272 [ -z "$1" ] && return
273 cvsps -q -s "$1" -g | cdiff
277 ps aux | grep "$@" | grep -v "grep $@"
281 # Idea from https://dataswamp.org/~solene/2021-03-25-computer-to-phone-text.html
282 xclip -o | qrencode -o - > ~/qrclip.png && sxiv -g 600x600 ~/qrclip.png && rm ~/qrclip.png
286 test -z "$1" && cd $HOME && ls -lh && return
291 pkglocate "$1" | cut -d ':' -f 1 | sort -u | fzf
295 [[ -n $1 ]] || return 0
296 [[ -d $1 ]] || mkdir -p "$1"
297 [[ -d $1 ]] && builtin cd "$1"
301 curl -OL --compressed "$@"
305 ifconfig | grep ieee | awk {'print $3'}
308 # Show infos about my external IP address
310 echo "My external IPv4 : $(ftp -4 -M -o - http://icanhazip.com 2> /dev/null)"
311 echo "My external IPv6 : $(ftp -6 -M -o - http://icanhazip.com 2> /dev/null)"
312 echo "My external PTR : $(ftp -M -o - http://icanhazptr.com 2> /dev/null)"
316 echo "scale=3;$@" | bc -l
319 # Copied from https://github.com/agkozak/polyglot/ MIT license
320 _polyglot_branch_status() {
321 POLYGLOT_REF="$(env git symbolic-ref --quiet HEAD 2> /dev/null)"
322 case $? in # See what the exit code is.
323 0) ;; # $POLYGLOT_REF contains the name of a checked-out branch.
324 128) return ;; # No Git repository here.
325 # Otherwise, see if HEAD is in a detached state.
326 *) POLYGLOT_REF="$(env git rev-parse --short HEAD 2> /dev/null)" || return ;;
329 if [ -n "$POLYGLOT_REF" ]; then
330 if [ "${POLYGLOT_SHOW_UNTRACKED:-1}" -eq 0 ]; then
331 POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status -uno 2>&1)
333 POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status 2>&1)
338 case $POLYGLOT_GIT_STATUS in
339 *' have diverged,'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&*" ;;
341 case $POLYGLOT_GIT_STATUS in
342 *'Your branch is behind '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&" ;;
344 case $POLYGLOT_GIT_STATUS in
345 *'Your branch is ahead of '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}*" ;;
347 case $POLYGLOT_GIT_STATUS in
348 *'new file: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}+" ;;
350 case $POLYGLOT_GIT_STATUS in
351 *'deleted: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}x" ;;
353 case $POLYGLOT_GIT_STATUS in
354 *'modified: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}!!" ;;
356 case $POLYGLOT_GIT_STATUS in
357 *'renamed: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}->" ;;
359 case $POLYGLOT_GIT_STATUS in
360 *'Untracked files:'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}?" ;;
363 [ -n "$POLYGLOT_SYMBOLS" ] && POLYGLOT_SYMBOLS=" $POLYGLOT_SYMBOLS"
365 printf ' (%s%s)' "${POLYGLOT_REF#refs/heads/}" "$POLYGLOT_SYMBOLS"
368 unset POLYGLOT_REF POLYGLOT_GIT_STATUS POLYGLOT_SYMBOLS
372 local _pf=${1:-/etc/pf.conf}
373 doas pfctl -n -f ${_pf} && doas pfctl -F rules && doas pfctl -f ${_pf}
376 # Disable history logging for this shell
382 TOG_COLORS=1 TERM=xterm /usr/local/bin/tog "$@"
385 # http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
387 export MARKPATH=$HOME/.marks
389 cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
392 mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
398 ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
401 #############################################################################
403 #############################################################################
406 # https://github.com/qbit/dotfiles/blob/master/common/dot_ksh_completions
408 if [ -d ~/.password-store ]; then
411 find . -type f -name \*.gpg | sed 's/^\.\///' | sed 's/\.gpg$//g'
414 set -A complete_tpm_1 -- $PASS_LIST usage
415 set -A complete_tpm_2 -- $PASS_LIST edit insert show rm
418 set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
420 set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)
422 if [ -d /var/db/pkg ]; then
423 PKG_LIST=$(/bin/ls -1 /var/db/pkg)
424 set -A complete_pkg_info -- $PKG_LIST
426 alias dpkgdel="doas pkg_delete"
427 set -A complete_dpkgdel_1 -- $PKG_LIST
430 # relayctl completion. Second level only for 'show'
431 set -A complete_relayctl_1 -- monitor show load poll reload stop redirect table host log
432 set -A complete_relayctl_2 -- summary hosts redirects relays routers sessions
434 set -A complete_unwindctl_1 -- reload log status
436 if [ -d /etc/rc.d ]; then
437 RCD_LIST=$(/bin/ls /etc/rc.d)
438 set -A complete_rcctl_1 -- get getdef set check reload restart stop start disable enable order ls
439 set -A complete_rcctl_2 -- $RCD_LIST
441 alias drcctl="doas rcctl"
442 set -A complete_drcctl_1 -- get getdef set check reload restart stop start disable enable order ls
443 set -A complete_drcctl_2 -- $RCD_LIST
446 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
448 set -A complete_got_1 -- $(got -h 2>&1 | sed -n s/commands://p)
450 # /tmp/.man-list is generated upon boot by /etc/rc.local with
451 # find /usr/share/man/ -type f | sed -e 's/.*\///' -e 's/\.[0-9]//' | sort -u
452 [[ -f /tmp/.man-list ]] && set -A complete_man -- $(cat /tmp/.man-list)
454 [[ -d $HOME/.marks ]] && set -A complete_j -- $(/bin/ls $HOME/.marks)
456 #############################################################################
458 #############################################################################
462 if [ $_temp -ne 0 ]; then
463 echo -n "\033[38;5;1m [$_temp]\033[m"
467 if [ -z "$SSH_CLIENT" ]; then
473 if [[ $(id -u) -eq 0 ]]; then
474 PS1='\h$PS1_TRENNER\\033[0;101m\u\\033[0m \w [$?]\n\$ '
475 elif [[ $(whoami) = "xhr" ]] || [[ $(whoami) = "matthiaschmidt" ]]; then
476 PS1='\h \w$(_polyglot_branch_status)$(_error_code) \033[38;5;11m\$\033[m '
478 PS1='\h$PS1_TRENNER\u \w$(_polyglot_branch_status) [$?]\n\$ '
481 #############################################################################
483 #############################################################################
487 #############################################################################
489 #############################################################################
491 [ -d $HOME/.keychain ] && . $HOME/.keychain/LWKA-6Q7VRN2-sh
493 LSCOLORS=Dxfxcxdxbxegedabagacad
495 HISTFILE=$HOME/.sh_history
496 HISTCONTROL=ignoredups:ignorespace
498 PATH=$HOME/Documents/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:$MACPATH
502 PKG_PATH=http://172.23.5.36/pub/OpenBSD/%c/packages/%a:http://ftp.hostserver.de/pub/OpenBSD/%c/packages/%a
504 # better two-finger touchpad scrolling
505 export MOZ_USE_XINPUT2=1
506 # opengl acceleration
507 export MOZ_ACCELERATED=1
508 # force webrender to enable
509 export MOZ_WEBRENDER=1
511 export PATH HOME TERM LSCOLORS HISTSIZE BLOCKSIZE PAGER LESSSECURE PKG_PATH FETCH_CMD