Blame


1 caf6781a 2021-01-06 xhr # sh/ksh initialization
2 caf6781a 2021-01-06 xhr
3 caf6781a 2021-01-06 xhr [ -f $HOME/.kshrc.private ] && . $HOME/.kshrc.private
4 caf6781a 2021-01-06 xhr
5 caf6781a 2021-01-06 xhr #############################################################################
6 caf6781a 2021-01-06 xhr # ALIASES
7 caf6781a 2021-01-06 xhr #############################################################################
8 caf6781a 2021-01-06 xhr
9 caf6781a 2021-01-06 xhr if command -v colorls > /dev/null ; then
10 8098ffa8 2022-05-29 xhr LS='colorls'
11 8098ffa8 2022-05-29 xhr export CLICOLOR=1
12 8098ffa8 2022-05-29 xhr else
13 8098ffa8 2022-05-29 xhr LS='ls'
14 caf6781a 2021-01-06 xhr fi
15 caf6781a 2021-01-06 xhr
16 caf6781a 2021-01-06 xhr if [[ $(uname -s) == "Linux" ]]; then
17 caf6781a 2021-01-06 xhr alias ls='ls --color=auto -h --file-type -s'
18 caf6781a 2021-01-06 xhr alias ll='ls -l'
19 caf6781a 2021-01-06 xhr alias rm='rm --preserve-root --one-file-system -I'
20 caf6781a 2021-01-06 xhr alias cps='sync ; cvs up ; sync'
21 caf6781a 2021-01-06 xhr if [ -x /usr/bin/dircolors ]; then
22 caf6781a 2021-01-06 xhr test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
23 caf6781a 2021-01-06 xhr fi
24 caf6781a 2021-01-06 xhr bind -m '^L'=clear'^J'
25 caf6781a 2021-01-06 xhr elif [[ $(uname -s) == "OpenBSD" ]]; then
26 caf6781a 2021-01-06 xhr alias ls='$LS'
27 caf6781a 2021-01-06 xhr alias ll='$LS -Flho'
28 caf6781a 2021-01-06 xhr alias cps='sync ; opencvs up ; sync'
29 caf6781a 2021-01-06 xhr
30 caf6781a 2021-01-06 xhr bind '^L'=clear-screen
31 caf6781a 2021-01-06 xhr
32 caf6781a 2021-01-06 xhr # Enable SIGINFO with ^T
33 caf6781a 2021-01-06 xhr stty status ^T
34 33ae4ce3 2022-09-08 xhr elif [[ $(uname -s) == "Darwin" ]]; then
35 33ae4ce3 2022-09-08 xhr alias ls='$LS -G'
36 33ae4ce3 2022-09-08 xhr alias ll='$LS -GFlho'
37 33ae4ce3 2022-09-08 xhr
38 33ae4ce3 2022-09-08 xhr bind '^L'=clear-screen
39 33ae4ce3 2022-09-08 xhr export MACPATH=/opt/homebrew/bin/:/opt/homebrew/sbin
40 caf6781a 2021-01-06 xhr elif [[ $(uname -s) == "FreeBSD" ]]; then
41 caf6781a 2021-01-06 xhr alias ls='$LS -G'
42 caf6781a 2021-01-06 xhr alias ll='$LS -GFlho'
43 caf6781a 2021-01-06 xhr
44 caf6781a 2021-01-06 xhr bind '^L'=clear-screen
45 caf6781a 2021-01-06 xhr
46 caf6781a 2021-01-06 xhr # Enable SIGINFO with ^T
47 caf6781a 2021-01-06 xhr stty status ^T
48 caf6781a 2021-01-06 xhr
49 caf6781a 2021-01-06 xhr export TERM=xterm-256color
50 caf6781a 2021-01-06 xhr fi
51 caf6781a 2021-01-06 xhr
52 f77246f9 2022-06-01 xhr if [[ $HIGHDPI -eq 1 ]]; then
53 f77246f9 2022-06-01 xhr alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+1430+300 --sub-scale=0.5'
54 f77246f9 2022-06-01 xhr else
55 f77246f9 2022-06-01 xhr alias mpv='mpv --no-audio-display --audio-channels=stereo --geometry=50%+950+200 --sub-scale=0.7'
56 f77246f9 2022-06-01 xhr fi
57 f77246f9 2022-06-01 xhr
58 6e553973 2022-04-26 xhr alias .2='cds ../..'
59 6e553973 2022-04-26 xhr alias .3='cds ../../..'
60 6e553973 2022-04-26 xhr alias .4='cds ../../../..'
61 caf6781a 2021-01-06 xhr alias j='jump'
62 caf6781a 2021-01-06 xhr alias c='cvs'
63 caf6781a 2021-01-06 xhr alias h='history -60 | sort -k2 | uniq -f2 | sort -bn'
64 caf6781a 2021-01-06 xhr alias sudo='sudo -H'
65 caf6781a 2021-01-06 xhr alias mc='mc --color'
66 caf6781a 2021-01-06 xhr alias pwgen='pwgen -s'
67 07664861 2021-01-19 xhr alias pkg_add='pkg_add -V'
68 caf6781a 2021-01-06 xhr alias dt='dtoggle'
69 caf6781a 2021-01-06 xhr alias tty-clock='tty-clock -s -c'
70 caf6781a 2021-01-06 xhr alias chromium='chromium --disk-cache-dir=/tmp'
71 caf6781a 2021-01-06 xhr alias open="xdg-open"
72 caf6781a 2021-01-06 xhr alias ffplay='ffplay -hide_banner'
73 caf6781a 2021-01-06 xhr alias gps='sync ; git pull ; sync'
74 caf6781a 2021-01-06 xhr alias cal='cal -m -w'
75 caf6781a 2021-01-06 xhr alias ed='ed -p*'
76 caf6781a 2021-01-06 xhr alias qw='pkill -9 xidle'
77 caf6781a 2021-01-06 xhr alias cc='cc -fdiagnostics-color'
78 caf6781a 2021-01-06 xhr alias weather='curl http://wttr.in/Karlsruhe'
79 dd3af197 2022-02-06 xhr alias dig='dig +noall +answer +comment'
80 6223de89 2021-12-10 xhr alias gdb='gdb -q'
81 444bd907 2021-12-28 xhr alias egdb='egdb -q'
82 caf6781a 2021-01-06 xhr
83 caf6781a 2021-01-06 xhr #############################################################################
84 caf6781a 2021-01-06 xhr # FUNCTIONS
85 caf6781a 2021-01-06 xhr #############################################################################
86 267dc0c6 2021-11-10 xhr
87 caf6781a 2021-01-06 xhr # Following three functions from "shell FU by Isaac Levy" presentation
88 caf6781a 2021-01-06 xhr yell() { echo "$0: $*" >&2; }
89 caf6781a 2021-01-06 xhr die() { yell "$*"; exit 111; }
90 caf6781a 2021-01-06 xhr try() { "$@" || die "cannot $*"; }
91 caf6781a 2021-01-06 xhr
92 60ed39b5 2022-01-14 xhr # Quick n dirty hack to generate a RSA key and a X509 cert
93 60ed39b5 2022-01-14 xhr gennewcert() {
94 60ed39b5 2022-01-14 xhr [[ -z "$1" ]] && echo "No alias provided" && return
95 60ed39b5 2022-01-14 xhr
96 60ed39b5 2022-01-14 xhr openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
97 60ed39b5 2022-01-14 xhr -keyout $1.key.pem -new -subj /CN=$1 -out $1.cert.pem \
98 60ed39b5 2022-01-14 xhr -addext subjectAltName=DNS:$1
99 60ed39b5 2022-01-14 xhr }
100 60ed39b5 2022-01-14 xhr
101 caf6781a 2021-01-06 xhr # Neat trick from https://github.com/lf94/peek-for-tmux/blob/master/README.md
102 caf6781a 2021-01-06 xhr p() {
103 caf6781a 2021-01-06 xhr tmux split-window -p 33 more $@ || exit;
104 caf6781a 2021-01-06 xhr }
105 caf6781a 2021-01-06 xhr
106 2a9e5229 2021-06-28 xhr g() {
107 2a9e5229 2021-06-28 xhr if [ -d ".got" ]; then
108 2a9e5229 2021-06-28 xhr got "$@"
109 2a9e5229 2021-06-28 xhr else
110 2a9e5229 2021-06-28 xhr git "$@"
111 51896f71 2021-12-28 xhr fi
112 67c208cf 2021-12-28 xhr }
113 67c208cf 2021-12-28 xhr
114 67c208cf 2021-12-28 xhr enablevideoconf() {
115 67c208cf 2021-12-28 xhr echo "[+] Enable video recording"
116 67c208cf 2021-12-28 xhr doas sysctl kern.video.record=1
117 67c208cf 2021-12-28 xhr echo "[+] Enable audio recording"
118 67c208cf 2021-12-28 xhr doas sysctl kern.audio.record=1
119 67c208cf 2021-12-28 xhr echo "[+] Set mic to mic2"
120 67c208cf 2021-12-28 xhr doas mixerctl record.adc-0:1_source=mic2
121 67c208cf 2021-12-28 xhr echo "[+] Adjust input level"
122 67c208cf 2021-12-28 xhr sndioctl input.level=0.25
123 67c208cf 2021-12-28 xhr }
124 67c208cf 2021-12-28 xhr
125 67c208cf 2021-12-28 xhr disablevideoconf() {
126 67c208cf 2021-12-28 xhr echo "[+] Disable video recording"
127 67c208cf 2021-12-28 xhr doas sysctl kern.video.record=0
128 67c208cf 2021-12-28 xhr echo "[+] Disable audio recording"
129 67c208cf 2021-12-28 xhr doas sysctl kern.audio.record=0
130 51896f71 2021-12-28 xhr }
131 51896f71 2021-12-28 xhr
132 51896f71 2021-12-28 xhr # Connect to a vmm(4) VM which uses the "local interface" networking scheme
133 51896f71 2021-12-28 xhr vmmssh() {
134 51896f71 2021-12-28 xhr if [ -z "$1" ]; then
135 51896f71 2021-12-28 xhr echo "Usage: vmmssh <name of the vmm VM> [user]"
136 51896f71 2021-12-28 xhr echo ""
137 51896f71 2021-12-28 xhr echo "If no user name is provided, root is used"
138 51896f71 2021-12-28 xhr return
139 51896f71 2021-12-28 xhr fi
140 51896f71 2021-12-28 xhr
141 51896f71 2021-12-28 xhr local _user="${2:-root}"
142 51896f71 2021-12-28 xhr local _id=$(vmctl show $1| tail -1 | awk '{ print $1}')
143 51896f71 2021-12-28 xhr
144 51896f71 2021-12-28 xhr if [ "${_id}" = "ID" ]; then
145 51896f71 2021-12-28 xhr echo "No VM named $1 found"
146 51896f71 2021-12-28 xhr return
147 2a9e5229 2021-06-28 xhr fi
148 51896f71 2021-12-28 xhr
149 cce4ab6c 2021-12-29 xhr ssh -o StrictHostKeyChecking=no -l ${_user} 100.64.${_id}.3
150 2a9e5229 2021-06-28 xhr }
151 2a9e5229 2021-06-28 xhr
152 caf6781a 2021-01-06 xhr checklatestsnap() {
153 25aece9a 2022-05-29 xhr ftp -MVo- http://172.23.5.36/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
154 86642edf 2021-09-22 xhr ftp -MVo- "$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)/BUILDINFO"
155 86642edf 2021-09-22 xhr ftp -MVo- http://ftp.openbsd.org/pub/OpenBSD/snapshots/$(uname -m)/BUILDINFO
156 caf6781a 2021-01-06 xhr }
157 caf6781a 2021-01-06 xhr
158 caf6781a 2021-01-06 xhr lostandfoundcheck() {
159 fdc3c907 2022-02-22 xhr for mp in $(mount -t ffs | cut -d ' ' -f 3); do
160 caf6781a 2021-01-06 xhr [[ -d ${mp}/lost+found ]] && echo "${mp}/lost+found exists"
161 caf6781a 2021-01-06 xhr done
162 94be960e 2022-03-30 xhr }
163 94be960e 2022-03-30 xhr
164 94be960e 2022-03-30 xhr kshrc() {
165 94be960e 2022-03-30 xhr . $HOME/.kshrc
166 caf6781a 2021-01-06 xhr }
167 caf6781a 2021-01-06 xhr
168 caf6781a 2021-01-06 xhr updatesrc() {
169 540ef4dd 2021-06-26 xhr if [ ! -d "/var/git" ]; then
170 540ef4dd 2021-06-26 xhr local _oldpwd="$PWD"
171 540ef4dd 2021-06-26 xhr cd /usr/src && {
172 540ef4dd 2021-06-26 xhr sync && git pull ; sync
173 540ef4dd 2021-06-26 xhr }
174 540ef4dd 2021-06-26 xhr cd /usr/ports && {
175 540ef4dd 2021-06-26 xhr sync && git pull ; sync
176 540ef4dd 2021-06-26 xhr }
177 540ef4dd 2021-06-26 xhr cd "$_oldpwd"
178 540ef4dd 2021-06-26 xhr else
179 540ef4dd 2021-06-26 xhr local _oldpwd="$PWD"
180 540ef4dd 2021-06-26 xhr cd /var/git/src.git && {
181 540ef4dd 2021-06-26 xhr sync && got fetch; sync
182 540ef4dd 2021-06-26 xhr }
183 003d21e6 2021-07-16 xhr cd /usr/src && {
184 003d21e6 2021-07-16 xhr sync && got up && sync
185 003d21e6 2021-07-16 xhr }
186 540ef4dd 2021-06-26 xhr cd /var/git/ports.git && {
187 540ef4dd 2021-06-26 xhr sync && got fetch; sync
188 540ef4dd 2021-06-26 xhr }
189 540ef4dd 2021-06-26 xhr cd /usr/ports && {
190 003d21e6 2021-07-16 xhr sync && got up && sync
191 540ef4dd 2021-06-26 xhr }
192 540ef4dd 2021-06-26 xhr cd "$_oldpwd"
193 540ef4dd 2021-06-26 xhr fi
194 caf6781a 2021-01-06 xhr }
195 caf6781a 2021-01-06 xhr
196 caf6781a 2021-01-06 xhr updatepkgs() {
197 caf6781a 2021-01-06 xhr local _option="" _args=$1
198 caf6781a 2021-01-06 xhr if [[ -n $(sysctl -n kern.version | cut -d ' ' -f2 | grep beta) ]]; then
199 caf6781a 2021-01-06 xhr _option="-D snap"
200 caf6781a 2021-01-06 xhr fi
201 caf6781a 2021-01-06 xhr
202 9ea26640 2021-08-13 xhr sync && doas pkg_add -ui $_option $_args
203 9ea26640 2021-08-13 xhr sync
204 9ea26640 2021-08-13 xhr
205 9ea26640 2021-08-13 xhr return
206 9ea26640 2021-08-13 xhr
207 003d21e6 2021-07-16 xhr if [ ! -d /var/pkg_mirror ]; then
208 003d21e6 2021-07-16 xhr doas mkdir /var/pkg_mirror
209 003d21e6 2021-07-16 xhr fi
210 003d21e6 2021-07-16 xhr doas mount_nfs -s -a 4 -T -r 32768 -w 32768 -o noatime,ro,intr mx.xosc.net:/pkg /var/pkg_mirror
211 003d21e6 2021-07-16 xhr doas umount /var/pkg_mirror/
212 caf6781a 2021-01-06 xhr }
213 caf6781a 2021-01-06 xhr
214 caf6781a 2021-01-06 xhr getbsdrd() {
215 caf6781a 2021-01-06 xhr local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
216 caf6781a 2021-01-06 xhr
217 caf6781a 2021-01-06 xhr ftp -V -o /tmp/bsd.rd "$_mirror/bsd.rd" || return 1
218 caf6781a 2021-01-06 xhr ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
219 caf6781a 2021-01-06 xhr
220 caf6781a 2021-01-06 xhr cd /tmp && signify -C -p "/etc/signify/openbsd-$(uname -r | tr -d '.')-base.pub" -x /tmp/SHA256.sig bsd.rd
221 caf6781a 2021-01-06 xhr }
222 caf6781a 2021-01-06 xhr
223 caf6781a 2021-01-06 xhr getbsdvm() {
224 caf6781a 2021-01-06 xhr local _mirror="$(egrep -m 1 "^(ftp|http|https)" /etc/installurl)/snapshots/$(uname -m)"
225 caf6781a 2021-01-06 xhr
226 caf6781a 2021-01-06 xhr ftp -V -o /tmp/bsd "$_mirror/bsd" || return 1
227 caf6781a 2021-01-06 xhr ftp -V -o /tmp/SHA256.sig "$_mirror/SHA256.sig" || return 1
228 caf6781a 2021-01-06 xhr
229 caf6781a 2021-01-06 xhr 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
230 caf6781a 2021-01-06 xhr }
231 caf6781a 2021-01-06 xhr
232 caf6781a 2021-01-06 xhr openports() {
233 003d21e6 2021-07-16 xhr local _filter1='internet'
234 003d21e6 2021-07-16 xhr local _filter2='icmp|raw|<-|->'
235 003d21e6 2021-07-16 xhr
236 003d21e6 2021-07-16 xhr if [ "$1" = "-4" ]; then
237 003d21e6 2021-07-16 xhr _filter2="internet6|${_filter2}"
238 003d21e6 2021-07-16 xhr elif [ "$1" = "-6" ]; then
239 003d21e6 2021-07-16 xhr _filter1="internet6"
240 003d21e6 2021-07-16 xhr fi
241 003d21e6 2021-07-16 xhr
242 003d21e6 2021-07-16 xhr printf "%-10s %-13s %-5s %-5s %-9s %s\n" "USER" "COMMAND" "PID" "PROTO" "FAMILY" "LOCAL ADDRESS"
243 003d21e6 2021-07-16 xhr fstat | grep "${_filter1}" | grep -vE "${_filter2}" | awk '{ printf("%-10s %-13s %5s %-5s %-9s %s\n", $1,$2,$3,$7,$5,$9); }' | sort -u
244 caf6781a 2021-01-06 xhr }
245 caf6781a 2021-01-06 xhr
246 caf6781a 2021-01-06 xhr psearch() {
247 caf6781a 2021-01-06 xhr local pt="/usr/ports"
248 caf6781a 2021-01-06 xhr
249 caf6781a 2021-01-06 xhr [[ -z ${1} ]] && echo "Need a keyword to search for" && return
250 caf6781a 2021-01-06 xhr [[ ! -d ${pt} ]] && echo "Cannot find ports tree" && return
251 caf6781a 2021-01-06 xhr
252 caf6781a 2021-01-06 xhr cd ${pt} && make search name=${1}
253 caf6781a 2021-01-06 xhr }
254 caf6781a 2021-01-06 xhr
255 caf6781a 2021-01-06 xhr sshopen() {
256 caf6781a 2021-01-06 xhr # The following is only needed on WSL not on other OSes
257 caf6781a 2021-01-06 xhr [ -f "/proc/version" ] && grep -qE "(Microsoft|WSL)" /proc/version 2> /dev/null
258 caf6781a 2021-01-06 xhr if [ $? -eq 0 ]; then
259 5ff5ff72 2022-06-02 xhr /usr/bin/keychain -q --nogui $HOME/.ssh/id_ed25519
260 5ff5ff72 2022-06-02 xhr return
261 caf6781a 2021-01-06 xhr fi
262 caf6781a 2021-01-06 xhr
263 caf6781a 2021-01-06 xhr # Find all public keys...
264 caf6781a 2021-01-06 xhr for i in $(find $HOME/.ssh/ -maxdepth 1 -name "*.pub"); do
265 caf6781a 2021-01-06 xhr # ... and strip the .pub suffix
266 caf6781a 2021-01-06 xhr _key=`echo $i | sed -e 's/\.pub//'`
267 caf6781a 2021-01-06 xhr command ssh-add $_key
268 caf6781a 2021-01-06 xhr done
269 caf6781a 2021-01-06 xhr }
270 caf6781a 2021-01-06 xhr
271 caf6781a 2021-01-06 xhr cvspsdiff() {
272 caf6781a 2021-01-06 xhr [ -z "$1" ] && return
273 caf6781a 2021-01-06 xhr cvsps -q -s "$1" -g | cdiff
274 caf6781a 2021-01-06 xhr }
275 caf6781a 2021-01-06 xhr
276 caf6781a 2021-01-06 xhr psg() {
277 f0843204 2021-04-21 xhr ps aux | grep "$@" | grep -v "grep $@"
278 caf6781a 2021-01-06 xhr }
279 caf6781a 2021-01-06 xhr
280 83809fd3 2021-05-05 xhr qrcodegen() {
281 83809fd3 2021-05-05 xhr # Idea from https://dataswamp.org/~solene/2021-03-25-computer-to-phone-text.html
282 83809fd3 2021-05-05 xhr xclip -o | qrencode -o - > ~/qrclip.png && sxiv -g 600x600 ~/qrclip.png && rm ~/qrclip.png
283 83809fd3 2021-05-05 xhr }
284 83809fd3 2021-05-05 xhr
285 caf6781a 2021-01-06 xhr cds() {
286 caf6781a 2021-01-06 xhr test -z "$1" && cd $HOME && ls -lh && return
287 caf6781a 2021-01-06 xhr cd "$1" && ls -lah
288 caf6781a 2021-01-06 xhr }
289 caf6781a 2021-01-06 xhr
290 caf6781a 2021-01-06 xhr pkg_search() {
291 1125314c 2022-01-03 xhr pkglocate "$1" | cut -d ':' -f 1 | sort -u | fzf
292 caf6781a 2021-01-06 xhr }
293 caf6781a 2021-01-06 xhr
294 caf6781a 2021-01-06 xhr mkcd() {
295 caf6781a 2021-01-06 xhr [[ -n $1 ]] || return 0
296 caf6781a 2021-01-06 xhr [[ -d $1 ]] || mkdir -p "$1"
297 caf6781a 2021-01-06 xhr [[ -d $1 ]] && builtin cd "$1"
298 caf6781a 2021-01-06 xhr }
299 caf6781a 2021-01-06 xhr
300 caf6781a 2021-01-06 xhr cget() {
301 caf6781a 2021-01-06 xhr curl -OL --compressed "$@"
302 caf6781a 2021-01-06 xhr }
303 caf6781a 2021-01-06 xhr
304 caf6781a 2021-01-06 xhr showwifi() {
305 caf6781a 2021-01-06 xhr ifconfig | grep ieee | awk {'print $3'}
306 caf6781a 2021-01-06 xhr }
307 caf6781a 2021-01-06 xhr
308 caf6781a 2021-01-06 xhr # Show infos about my external IP address
309 caf6781a 2021-01-06 xhr showmyipaddress() {
310 caf6781a 2021-01-06 xhr echo "My external IPv4 : $(ftp -4 -M -o - http://icanhazip.com 2> /dev/null)"
311 caf6781a 2021-01-06 xhr echo "My external IPv6 : $(ftp -6 -M -o - http://icanhazip.com 2> /dev/null)"
312 caf6781a 2021-01-06 xhr echo "My external PTR : $(ftp -M -o - http://icanhazptr.com 2> /dev/null)"
313 caf6781a 2021-01-06 xhr }
314 caf6781a 2021-01-06 xhr
315 caf6781a 2021-01-06 xhr calc() {
316 caf6781a 2021-01-06 xhr echo "scale=3;$@" | bc -l
317 caf6781a 2021-01-06 xhr }
318 caf6781a 2021-01-06 xhr
319 377cb53e 2021-10-28 matthias. # Copied from https://github.com/agkozak/polyglot/ MIT license
320 377cb53e 2021-10-28 matthias. _polyglot_branch_status() {
321 377cb53e 2021-10-28 matthias. POLYGLOT_REF="$(env git symbolic-ref --quiet HEAD 2> /dev/null)"
322 377cb53e 2021-10-28 matthias. case $? in # See what the exit code is.
323 377cb53e 2021-10-28 matthias. 0) ;; # $POLYGLOT_REF contains the name of a checked-out branch.
324 377cb53e 2021-10-28 matthias. 128) return ;; # No Git repository here.
325 377cb53e 2021-10-28 matthias. # Otherwise, see if HEAD is in a detached state.
326 377cb53e 2021-10-28 matthias. *) POLYGLOT_REF="$(env git rev-parse --short HEAD 2> /dev/null)" || return ;;
327 377cb53e 2021-10-28 matthias. esac
328 377cb53e 2021-10-28 matthias.
329 377cb53e 2021-10-28 matthias. if [ -n "$POLYGLOT_REF" ]; then
330 377cb53e 2021-10-28 matthias. if [ "${POLYGLOT_SHOW_UNTRACKED:-1}" -eq 0 ]; then
331 377cb53e 2021-10-28 matthias. POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status -uno 2>&1)
332 377cb53e 2021-10-28 matthias. else
333 377cb53e 2021-10-28 matthias. POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status 2>&1)
334 377cb53e 2021-10-28 matthias. fi
335 377cb53e 2021-10-28 matthias.
336 377cb53e 2021-10-28 matthias. POLYGLOT_SYMBOLS=''
337 377cb53e 2021-10-28 matthias.
338 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
339 377cb53e 2021-10-28 matthias. *' have diverged,'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&*" ;;
340 377cb53e 2021-10-28 matthias. esac
341 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
342 377cb53e 2021-10-28 matthias. *'Your branch is behind '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&" ;;
343 377cb53e 2021-10-28 matthias. esac
344 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
345 377cb53e 2021-10-28 matthias. *'Your branch is ahead of '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}*" ;;
346 377cb53e 2021-10-28 matthias. esac
347 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
348 377cb53e 2021-10-28 matthias. *'new file: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}+" ;;
349 377cb53e 2021-10-28 matthias. esac
350 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
351 377cb53e 2021-10-28 matthias. *'deleted: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}x" ;;
352 377cb53e 2021-10-28 matthias. esac
353 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
354 377cb53e 2021-10-28 matthias. *'modified: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}!!" ;;
355 377cb53e 2021-10-28 matthias. esac
356 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
357 377cb53e 2021-10-28 matthias. *'renamed: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}->" ;;
358 377cb53e 2021-10-28 matthias. esac
359 377cb53e 2021-10-28 matthias. case $POLYGLOT_GIT_STATUS in
360 377cb53e 2021-10-28 matthias. *'Untracked files:'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}?" ;;
361 377cb53e 2021-10-28 matthias. esac
362 377cb53e 2021-10-28 matthias.
363 377cb53e 2021-10-28 matthias. [ -n "$POLYGLOT_SYMBOLS" ] && POLYGLOT_SYMBOLS=" $POLYGLOT_SYMBOLS"
364 377cb53e 2021-10-28 matthias.
365 377cb53e 2021-10-28 matthias. printf ' (%s%s)' "${POLYGLOT_REF#refs/heads/}" "$POLYGLOT_SYMBOLS"
366 377cb53e 2021-10-28 matthias. fi
367 377cb53e 2021-10-28 matthias.
368 377cb53e 2021-10-28 matthias. unset POLYGLOT_REF POLYGLOT_GIT_STATUS POLYGLOT_SYMBOLS
369 7c340db1 2021-10-23 xhr }
370 7c340db1 2021-10-23 xhr
371 caf6781a 2021-01-06 xhr lpf() {
372 caf6781a 2021-01-06 xhr local _pf=${1:-/etc/pf.conf}
373 caf6781a 2021-01-06 xhr doas pfctl -n -f ${_pf} && doas pfctl -F rules && doas pfctl -f ${_pf}
374 caf6781a 2021-01-06 xhr }
375 caf6781a 2021-01-06 xhr
376 caf6781a 2021-01-06 xhr # Disable history logging for this shell
377 caf6781a 2021-01-06 xhr nohistory() {
378 caf6781a 2021-01-06 xhr HISTFILE=/dev/null
379 caf6781a 2021-01-06 xhr }
380 caf6781a 2021-01-06 xhr
381 caf6781a 2021-01-06 xhr tog() {
382 caf6781a 2021-01-06 xhr TOG_COLORS=1 TERM=xterm /usr/local/bin/tog "$@"
383 caf6781a 2021-01-06 xhr }
384 caf6781a 2021-01-06 xhr
385 caf6781a 2021-01-06 xhr # http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
386 caf6781a 2021-01-06 xhr
387 caf6781a 2021-01-06 xhr export MARKPATH=$HOME/.marks
388 caf6781a 2021-01-06 xhr jump() {
389 caf6781a 2021-01-06 xhr cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
390 caf6781a 2021-01-06 xhr }
391 caf6781a 2021-01-06 xhr mark() {
392 caf6781a 2021-01-06 xhr mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
393 caf6781a 2021-01-06 xhr }
394 caf6781a 2021-01-06 xhr unmark() {
395 caf6781a 2021-01-06 xhr rm -i "$MARKPATH/$1"
396 caf6781a 2021-01-06 xhr }
397 caf6781a 2021-01-06 xhr marks() {
398 caf6781a 2021-01-06 xhr ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
399 caf6781a 2021-01-06 xhr }
400 caf6781a 2021-01-06 xhr
401 caf6781a 2021-01-06 xhr #############################################################################
402 caf6781a 2021-01-06 xhr # COMPLETIONS
403 caf6781a 2021-01-06 xhr #############################################################################
404 caf6781a 2021-01-06 xhr
405 caf6781a 2021-01-06 xhr # Mostly copied from
406 caf6781a 2021-01-06 xhr # https://github.com/qbit/dotfiles/blob/master/common/dot_ksh_completions
407 caf6781a 2021-01-06 xhr
408 caf6781a 2021-01-06 xhr if [ -d ~/.password-store ]; then
409 caf6781a 2021-01-06 xhr PASS_LIST=$(
410 caf6781a 2021-01-06 xhr cd ~/.password-store
411 caf6781a 2021-01-06 xhr find . -type f -name \*.gpg | sed 's/^\.\///' | sed 's/\.gpg$//g'
412 caf6781a 2021-01-06 xhr )
413 caf6781a 2021-01-06 xhr
414 caf6781a 2021-01-06 xhr set -A complete_tpm_1 -- $PASS_LIST usage
415 caf6781a 2021-01-06 xhr set -A complete_tpm_2 -- $PASS_LIST edit insert show rm
416 caf6781a 2021-01-06 xhr fi
417 caf6781a 2021-01-06 xhr
418 caf6781a 2021-01-06 xhr set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
419 caf6781a 2021-01-06 xhr
420 caf6781a 2021-01-06 xhr set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)
421 caf6781a 2021-01-06 xhr
422 caf6781a 2021-01-06 xhr if [ -d /var/db/pkg ]; then
423 caf6781a 2021-01-06 xhr PKG_LIST=$(/bin/ls -1 /var/db/pkg)
424 caf6781a 2021-01-06 xhr set -A complete_pkg_info -- $PKG_LIST
425 c5a18514 2021-04-21 xhr
426 c5a18514 2021-04-21 xhr alias dpkgdel="doas pkg_delete"
427 c5a18514 2021-04-21 xhr set -A complete_dpkgdel_1 -- $PKG_LIST
428 caf6781a 2021-01-06 xhr fi
429 ff408f72 2021-06-17 matthias.
430 ff408f72 2021-06-17 matthias. # relayctl completion. Second level only for 'show'
431 ff408f72 2021-06-17 matthias. set -A complete_relayctl_1 -- monitor show load poll reload stop redirect table host log
432 ff408f72 2021-06-17 matthias. set -A complete_relayctl_2 -- summary hosts redirects relays routers sessions
433 caf6781a 2021-01-06 xhr
434 ff408f72 2021-06-17 matthias. set -A complete_unwindctl_1 -- reload log status
435 ff408f72 2021-06-17 matthias.
436 caf6781a 2021-01-06 xhr if [ -d /etc/rc.d ]; then
437 55fd2977 2021-04-21 xhr RCD_LIST=$(/bin/ls /etc/rc.d)
438 55fd2977 2021-04-21 xhr set -A complete_rcctl_1 -- get getdef set check reload restart stop start disable enable order ls
439 55fd2977 2021-04-21 xhr set -A complete_rcctl_2 -- $RCD_LIST
440 caf6781a 2021-01-06 xhr
441 caf6781a 2021-01-06 xhr alias drcctl="doas rcctl"
442 caf6781a 2021-01-06 xhr set -A complete_drcctl_1 -- get getdef set check reload restart stop start disable enable order ls
443 55fd2977 2021-04-21 xhr set -A complete_drcctl_2 -- $RCD_LIST
444 caf6781a 2021-01-06 xhr fi
445 caf6781a 2021-01-06 xhr
446 caf6781a 2021-01-06 xhr 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
447 caf6781a 2021-01-06 xhr
448 3922435f 2021-12-05 xhr set -A complete_got_1 -- $(got -h 2>&1 | sed -n s/commands://p)
449 3922435f 2021-12-05 xhr
450 caf6781a 2021-01-06 xhr # /tmp/.man-list is generated upon boot by /etc/rc.local with
451 caf6781a 2021-01-06 xhr # find /usr/share/man/ -type f | sed -e 's/.*\///' -e 's/\.[0-9]//' | sort -u
452 caf6781a 2021-01-06 xhr [[ -f /tmp/.man-list ]] && set -A complete_man -- $(cat /tmp/.man-list)
453 caf6781a 2021-01-06 xhr
454 caf6781a 2021-01-06 xhr [[ -d $HOME/.marks ]] && set -A complete_j -- $(/bin/ls $HOME/.marks)
455 caf6781a 2021-01-06 xhr
456 caf6781a 2021-01-06 xhr #############################################################################
457 caf6781a 2021-01-06 xhr # PROMPT
458 caf6781a 2021-01-06 xhr #############################################################################
459 377cb53e 2021-10-28 matthias.
460 3329c032 2022-05-29 xhr _error_code() {
461 3329c032 2022-05-29 xhr local _temp=$?
462 3329c032 2022-05-29 xhr if [ $_temp -ne 0 ]; then
463 3329c032 2022-05-29 xhr echo -n "\033[38;5;1m [$_temp]\033[m"
464 3329c032 2022-05-29 xhr fi
465 3329c032 2022-05-29 xhr }
466 377cb53e 2021-10-28 matthias.
467 caf6781a 2021-01-06 xhr if [ -z "$SSH_CLIENT" ]; then
468 caf6781a 2021-01-06 xhr PS1_TRENNER="!!"
469 caf6781a 2021-01-06 xhr else
470 caf6781a 2021-01-06 xhr PS1_TRENNER="@"
471 caf6781a 2021-01-06 xhr fi
472 caf6781a 2021-01-06 xhr
473 caf6781a 2021-01-06 xhr if [[ $(id -u) -eq 0 ]]; then
474 caf6781a 2021-01-06 xhr PS1='\h$PS1_TRENNER\\033[0;101m\u\\033[0m \w [$?]\n\$ '
475 957edac5 2022-06-02 xhr elif [[ $(whoami) = "xhr" ]] || [[ $(whoami) = "matthiaschmidt" ]]; then
476 3329c032 2022-05-29 xhr PS1='\h \w$(_polyglot_branch_status)$(_error_code) \033[38;5;11m\$\033[m '
477 caf6781a 2021-01-06 xhr else
478 377cb53e 2021-10-28 matthias. PS1='\h$PS1_TRENNER\u \w$(_polyglot_branch_status) [$?]\n\$ '
479 caf6781a 2021-01-06 xhr fi
480 caf6781a 2021-01-06 xhr
481 caf6781a 2021-01-06 xhr #############################################################################
482 5f9e8be1 2021-07-16 xhr # MISC SETTINGS
483 5f9e8be1 2021-07-16 xhr #############################################################################
484 5f9e8be1 2021-07-16 xhr
485 5f9e8be1 2021-07-16 xhr set bell-style none
486 5f9e8be1 2021-07-16 xhr
487 5f9e8be1 2021-07-16 xhr #############################################################################
488 caf6781a 2021-01-06 xhr # VARIABLES
489 caf6781a 2021-01-06 xhr #############################################################################
490 caf6781a 2021-01-06 xhr
491 5ff5ff72 2022-06-02 xhr [ -d $HOME/.keychain ] && . $HOME/.keychain/LWKA-6Q7VRN2-sh
492 5ff5ff72 2022-06-02 xhr
493 caf6781a 2021-01-06 xhr LSCOLORS=Dxfxcxdxbxegedabagacad
494 3012dead 2022-01-30 xhr HISTSIZE=30000
495 caf6781a 2021-01-06 xhr HISTFILE=$HOME/.sh_history
496 6e9de349 2021-07-16 xhr HISTCONTROL=ignoredups:ignorespace
497 caf6781a 2021-01-06 xhr BLOCKSIZE=M
498 33ae4ce3 2022-09-08 xhr PATH=$HOME/Documents/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:$MACPATH
499 caf6781a 2021-01-06 xhr LESSSECURE=1
500 caf6781a 2021-01-06 xhr PAGER='less -JWAceX'
501 caf6781a 2021-01-06 xhr LESS='-Xa'
502 25aece9a 2022-05-29 xhr PKG_PATH=http://172.23.5.36/pub/OpenBSD/%c/packages/%a:http://ftp.hostserver.de/pub/OpenBSD/%c/packages/%a
503 291deb6d 2022-01-16 xhr
504 291deb6d 2022-01-16 xhr # better two-finger touchpad scrolling
505 291deb6d 2022-01-16 xhr export MOZ_USE_XINPUT2=1
506 291deb6d 2022-01-16 xhr # opengl acceleration
507 291deb6d 2022-01-16 xhr export MOZ_ACCELERATED=1
508 291deb6d 2022-01-16 xhr # force webrender to enable
509 291deb6d 2022-01-16 xhr export MOZ_WEBRENDER=1
510 291deb6d 2022-01-16 xhr
511 003d21e6 2021-07-16 xhr export PATH HOME TERM LSCOLORS HISTSIZE BLOCKSIZE PAGER LESSSECURE PKG_PATH FETCH_CMD