dotfiles/.kshrc

339 lines
9.5 KiB
Plaintext
Raw Normal View History

2022-12-04 22:59:34 +01:00
# ksh environment file
########################################################################
# ENVIRONMENT VARIABLES
########################################################################
### SEARCH PATHS
2023-02-16 10:12:03 +01:00
PATH=~/.bin\
2023-04-06 17:48:14 +02:00
:~/.local/bin\
2022-12-04 22:59:34 +01:00
:/bin\
:/sbin\
:/usr/bin\
:/usr/sbin\
:/usr/local/bin\
:/usr/local/sbin\
:/usr/X11R6/bin\
:/usr/games\
2023-02-16 10:12:03 +01:00
:/usr/ports/infrastructure/bin
2022-12-17 10:27:50 +01:00
JAVA_HOME=/usr/local/jdk-11/bin
PATH=${PATH}:${JAVA_HOME}
2022-12-04 22:59:34 +01:00
export PATH
### LANGUAGE
LANG=en_US.UTF-8
LC_MESSAGES=C
LC_NUMERIC=C
LC_TIME=de_DE.UTF-8
2022-12-04 22:59:34 +01:00
export LANG LC_ALL LC_MESSAGES LC_NUMERIC LC_TIME
### SOFTWARE PREFERENCES
EDITOR="vim"
VISUAL="vim"
BROWSER="chrome"
PAGER="less"
export EDITOR VISUAL BROWSER PAGER
PRINTER="rp"
export PRINTER
2022-12-04 22:59:34 +01:00
########################################################################
# STOP HERE IF NON INTERACTIVE
########################################################################
[[ $- != *i* ]] && return
########################################################################
# MANDATORY ENVIRONMENT
2022-12-04 22:59:34 +01:00
########################################################################
### HISTORY
HISTCONTROL=ignoredups:ignorespace:erasedups
HISTFILE=$HOME/.ksh-history
HISTSIZE=2000
export HISTCONTROL HISTFILE HISTSIZE
# LESS
2023-01-10 22:18:46 +01:00
LESS="-giJmR--tilde"
2022-12-04 22:59:34 +01:00
LESSHISTFILE="$HOME/.less-history"
export LESS LESSHISTFILE
########################################################################
# MODULE LOADER
########################################################################
2022-12-04 22:59:34 +01:00
load() { [ -f ~/.ksh/$1 ] && . ~/.ksh/$1; }
2022-12-04 22:59:34 +01:00
load environment.ksh
load aliases.ksh
load email.ksh
load porttools.ksh
load remind.ksh
load ytdl.ksh
2022-12-04 22:59:34 +01:00
########################################################################
# PROMPT (SIMPLE)
########################################################################
2023-01-10 22:18:46 +01:00
PS1="\h|\${?}\w\\$ "
2022-12-04 22:59:34 +01:00
########################################################################
# SHELL SETTINGS
########################################################################
ulimit -c 0
stty -ixon -ixoff
set -o emacs
set bell-style none
########################################################################
# ALIASES
########################################################################
2023-01-10 22:18:46 +01:00
# mastodon
2023-01-21 16:52:02 +01:00
alias toot-sh="toot-wrapper sh@bsd.network"
alias toot-uug="toot-wrapper uugrn@chaos.social"
2023-02-16 10:12:03 +01:00
tuta() {
tut -u "sh@bsd.network uugrn@chaos.social"
}
2023-01-13 13:46:11 +01:00
2022-12-04 22:59:34 +01:00
# system
alias sudo="doas"
alias su="doas su"
# packages
alias pkg_add="doas \pkg_add ${PKGOPT}"
alias pkg_delete="doas \pkg_delete ${PKGOPT}"
alias pkg_info="\pkg_info ${PKGOPT}"
2023-01-10 22:18:46 +01:00
pkg_reset() { pkg_delete -cIX $(</home/sdk/.pkglist); }
2022-12-04 22:59:34 +01:00
2023-01-10 22:18:46 +01:00
# servers
x() { printf '\033]0;$ ssh home.codevoid.de\007' \
&& ssh -t home.codevoid.de 'tmux -u attach || tmux -u'; }
t() { printf '\033]0;$ ssh tweety.home.codevoid.de\007' \
&& ssh -t -J home.codevoid.de \
tweety.home.codevoid.de 'tmux -u attach || tmux -u'; }
o() { printf '\033]0;$ ssh cvs.openbsd.org\007' \
&& ssh -t -J home.codevoid.de \
cvs.openbsd.org 'tmux -u attach || tmux -u'; }
2022-12-04 22:59:34 +01:00
2023-01-10 22:18:46 +01:00
scr() { [ -z "$1" ] && doas wsconsctl -n display.brightness \
|| doas wsconsctl display.brightness="$1"; }
2022-12-04 22:59:34 +01:00
# mount
alias mount_msdos="doas \mount_msdos -o nodev,nosuid,noatime -u 1000 -g 1000"
mount_tank() { awk '$3=="nfs"{print $2}' /etc/fstab | xargs -n1 doas mount; }
umount_tank() { awk '$3=="nfs"{print $2}' /etc/fstab | xargs -n1 doas umount; }
2023-01-11 09:38:57 +01:00
pw() { pwgen -1 -y --remove-chars=\~\`\"\'{}\(\)\[\]\*.\;\|,\<\> 22; }
2022-12-04 22:59:34 +01:00
# monitoring
lr() {
2022-12-13 23:16:23 +01:00
[ -z "$1" ] && return 2
[ -z "$2" ] \
&& ssh -t "$1" -- doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
|| ssh -t "$1" -- doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
| fgrep -i "$2"
2022-12-04 22:59:34 +01:00
}
l() {
2022-12-13 23:16:23 +01:00
[ -z "$1" ] \
&& doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
|| doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
| fgrep -i "$1"
2022-12-04 22:59:34 +01:00
}
2023-01-15 09:30:39 +01:00
# cam
2023-04-10 13:00:38 +02:00
alias camformats="ffplay -f v4l2 -list_formats all -i /dev/video"
2023-03-28 18:19:41 +02:00
alias cam="ffplay -loglevel quiet -f v4l2 -input_format mjpeg -video_size 640x480 -i /dev/video"
setcam() {
_dev=$1
echo ln -sf /dev/video${_dev:=0} /dev/video
doas ln -sf /dev/video${_dev:=0} /dev/video
}
2023-04-01 21:49:50 +02:00
alias mypkg_add="PKG_PATH=http://openbsd.codevoid.de/pub/OpenBSD/snapshots/packages/amd64 pkg_add -Dsnap -Dunsigned"
alias mypkg_info="PKG_PATH=http://openbsd.codevoid.de/pub/OpenBSD/snapshots/packages/amd64 pkg_info -Dsnap -Dunsigned"
openbsd-gitupdate() {
cd ~/code/OpenBSD/src && git pull
cd ~/code/OpenBSD/ports && git pull
cd ~/code/OpenBSD/xenocara && git pull
cd ~/code/OpenBSD
}
# mygdb <breakpoint> <program> <arguments>
mygdb() {
[ -z $3 ] \
&& echo "mygdb <breakpoint> <program> <arguments>" \
&& return
break="$1"; shift; prog="$1"; shift; args="$@";
egdb -ex "break $break" -ex "run $args" $prog
}
2022-12-13 23:16:23 +01:00
########################################################################
# KERNEL STUFF
########################################################################
2022-12-04 22:59:34 +01:00
2022-12-13 23:16:23 +01:00
alias update-ksh="cd /usr/src/bin/ksh \
&& doas make clean \
&& doas make obj \
&& doas make -j $MAKE_JOBS \
2022-12-13 23:16:23 +01:00
&& doas make install"
2022-12-04 22:59:34 +01:00
########################################################################
# TWITCH FROM CLI
########################################################################
alias twitch-play="mpv https://www.twitch.tv/c0dev0id"
twitch-stream() {
local API_KEY=$(pass Internet/Twitch | head -1)
local RES=$(xrandr | grep "*+" | awk '{print $1}')
local FAUX_OPTS="-d snd/default -m -vmic 5.0 -vmon 0.2 -r $RES -f 20 -b 4000"
2022-12-13 23:16:23 +01:00
fauxstream $FAUX_OPTS rtmp://live-ams.twitch.tv/app/$API_KEY
2022-12-04 22:59:34 +01:00
}
########################################################################
# DOTFILES WITH GIT
########################################################################
2022-12-17 23:03:45 +01:00
alias config='git --git-dir=${HOME}/.cfg/ --work-tree=${HOME}'
2022-12-04 22:59:34 +01:00
dotfiles_autoupdate() {
config add -u && \
config commit -m "Update $(date +"%Y-%m-%d %H:%M") \
2023-04-14 16:46:39 +02:00
$(uname -s)/$(uname -m)-$(hostname -s)" && config push
2022-12-04 22:59:34 +01:00
}
dotfiles_init() {
git --no-replace-objects clone --bare --depth 1 \
2023-01-10 14:18:52 +01:00
_gitea@git.uugrn.org:sdk/dotfiles.git $HOME/.cfg;
2022-12-04 22:59:34 +01:00
config config --local status.showUntrackedFiles no;
config checkout -f
}
########################################################################
# FILE SHARING
########################################################################
2022-12-13 23:16:23 +01:00
doupload-http() {
[ ! -f "$1" ] && return 2
chmod ugo+r "$1"
_name=$(basename "$1");
scp -r "$1" codevoid.de:/tmp
ssh codevoid.de "doas mv /tmp/$_name /home/www/htdocs/http/$_name"
echo "https://codevoid.de/h/$_name";
}
2023-01-10 22:18:46 +01:00
2022-12-13 23:16:23 +01:00
doupload-gopher() {
[ ! -f "$1" ] && return 2
chmod ugo+r "$1"
_name=$(basename "$1");
scp -r "$1" codevoid.de:/tmp
ssh codevoid.de "doas mv /tmp/$_name /home/www/htdocs/gopher/p/$_name"
case "$(file --mime-type -b "$1")" in
image/*) S="I";;
text/*) S="0";;
message/*) S="0";;
*/x-shellscript) S="0";;
*/pgp-keys) S="0";;
application/*) S="9";;
esac
echo "https://codevoid.de/$S/p/$_name";
echo "gopher://codevoid.de/$S/p/$_name";
2022-12-04 22:59:34 +01:00
}
########################################################################
# KSH COMPLETIONS
########################################################################
[ -f $HOME/.ksh-complete ] && . $HOME/.ksh-complete
2022-12-04 22:59:34 +01:00
########################################################################
# SCREEN CONFIGURATION
########################################################################
xr_primary() {
xrandr --listmonitors | awk '/ 0:/{ print $4 }'
}
xr_secondary() {
xrandr | awk '/ connected/ { print $1 }' | fgrep -v $(xr_primary)
}
xr_off() {
xrandr | awk '/disconnected/ { print $1 }'
}
2022-12-13 23:16:23 +01:00
2023-01-24 08:31:39 +01:00
xrandr_list() {
echo "primary: " $(xr_primary)
echo "secondary:" $(xr_secondary)
echo "offline: " $(xr_off)
}
2022-12-04 22:59:34 +01:00
xrandr_set() {
2023-04-01 21:49:50 +02:00
set -x
2022-12-04 22:59:34 +01:00
for scr in $(xr_secondary)
do
2023-04-09 09:28:48 +02:00
xrandr --output $scr --$1 $(xr_primary) --$2 $3
2022-12-04 22:59:34 +01:00
done
for scr in $(xr_off)
do
xrandr --output $scr --off
done
}
2023-01-24 08:31:39 +01:00
xrandr_only_primary() {
pri=$(xr_primary)
sec=$(xr_secondary)
off=$(xr_off)
set -x
xrandr --output $pri --auto
for scr in $sec $off
do
xrandr --output $scr --off
done
}
2022-12-04 22:59:34 +01:00
xrandr_mirror() {
xrandr_set same-as auto
}
xrandr_mirror_hd() {
2023-04-09 09:28:48 +02:00
xrandr_set same-as mode 1920x1080
2022-12-04 22:59:34 +01:00
}
xrandr_extend_above() {
2023-04-09 09:28:48 +02:00
xrandr_set above auto
2022-12-04 22:59:34 +01:00
}
xrandr_extend_right() {
2023-04-09 09:28:48 +02:00
xrandr_set right-of auto
2022-12-04 22:59:34 +01:00
}
xrandr_extend_left() {
2023-04-09 09:28:48 +02:00
xrandr_set left-of auto
2022-12-04 22:59:34 +01:00
}
xrandr_native() {
xrandr --output $(xr_primary) --auto
}
xrandr_720p() {
xrandr --output $(xr_primary) --mode 1280x720
}
xrandr_1080p() {
xrandr --output $(xr_primary) --mode 1920x1080
}
xrandr_4k() {
xrandr --output $(xr_primary) --mode 3840x2160
}
2023-01-10 22:18:46 +01:00
alias xrandr_portrait="xrandr --output DP-1 --rotate left"
2023-04-09 09:28:48 +02:00
alias xrandr_mirror_hdmi="xrandr --output HDMI-A-0 --same-as eDP --mode 1920x1080"
2022-12-13 23:16:23 +01:00
2022-12-04 22:59:34 +01:00
########################################################################
# GNUPG AGENT
########################################################################
#eval $(keychain -Q -q --noask --agents ssh,gpg --noask --eval --eval id_rsa id_dsa id_ed25519)
if [ -f $HOME/.enable_gpg ]
then
GPG_TTY=$(tty)
SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
SSH_AUTH_SOCK_EXTRA=${SSH_AUTH_SOCK%%.ssh}.extra
export GPG_TTY SSH_AUTH_SOCK SSH_AUTH_SOCK_EXTRA
pgrep -qu sdk gpg-agent || gpg-connect-agent -q /bye
fi