3 7b4d8efb 2022-02-04 op OpenBSD ksh (sometimes called opdksh or oksh) is the default shell on
4 7b4d8efb 2022-02-04 op OpenBSD, and is generally my go-to choince on other systems too. It has
5 7b4d8efb 2022-02-04 op a good ratio of features and simplicity
7 7b4d8efb 2022-02-04 op if [ "$TERM" = dumb ]; then
12 7b4d8efb 2022-02-04 op Enable emacs-like command editing regardless of $EDITOR and csh-like
13 7b4d8efb 2022-02-04 op history expansion with !
16 7b4d8efb 2022-02-04 op set -o csh-history
18 7b4d8efb 2022-02-04 op Talking about history, by default ksh won't store any, which is
19 7b4d8efb 2022-02-04 op unfortunate. I can't live without my C-r working!
21 7b4d8efb 2022-02-04 op HISTCONTROL=ignoredups:ignorespace
22 7b4d8efb 2022-02-04 op HISTFILE=$HOME/.history
23 7b4d8efb 2022-02-04 op HISTSIZE=10000
25 7b4d8efb 2022-02-04 op OpenBSD ksh has a limited support for programmed completions through
26 7b4d8efb 2022-02-04 op static lists. The completions are provided via an array called
27 7b4d8efb 2022-02-04 op complete_$progname; or complete_$progname_$nth for the nth argument.
29 7b4d8efb 2022-02-04 op Here's the completions for ssh and scp:
31 7b4d8efb 2022-02-04 op HOST_LIST=$(awk '/Host / {print $2}' ~/.ssh/config | xargs echo)
33 7b4d8efb 2022-02-04 op set -A complete_ssh -- $HOST_LIST
34 7b4d8efb 2022-02-04 op set -A complete_scp -- $HOST_LIST
36 7b4d8efb 2022-02-04 op and for kill(1) and pkill(1)
38 7b4d8efb 2022-02-04 op set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
39 7b4d8efb 2022-02-04 op set -A complete_pkill_2 -- -SIGHUP -SIGUSR1 -SIGUSR2 -SIGTERM -SIGKILL
41 7b4d8efb 2022-02-04 op and for vmd(8) if available
43 272ebe03 2022-09-16 op if test -f /usr/sbin/vmd && pgrep -fq /usr/sbin/vmd; then
44 7b4d8efb 2022-02-04 op set -A complete_vmctl_1 -- console load reload start stop \
45 7b4d8efb 2022-02-04 op reset status send receive
46 7b4d8efb 2022-02-04 op set -A complete_vmctl -- \
47 7b4d8efb 2022-02-04 op $(vmctl status | awk '!/NAME/{printf "%s ", $NF}')
50 7b4d8efb 2022-02-04 op and for ifconfig(8)
52 272ebe03 2022-09-16 op command -v ifconfig >/dev/null && \
53 272ebe03 2022-09-16 op set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)
55 7b4d8efb 2022-02-04 op and for got(1)
57 b142858f 2022-07-29 op command -v got >/dev/null && \
58 b142858f 2022-07-29 op set -A complete_got_1 -- $(got -h 2>&1 | sed -n s/commands://p)
60 7b4d8efb 2022-02-04 op Tweak the output of ls
62 7b4d8efb 2022-02-04 op alias ls='ls -F'
64 29db7106 2022-09-15 op Provide an easiest access to amused
66 29db7106 2022-09-15 op alias a=amused
72 a517421f 2023-09-01 op TCL manpages on OpenBSD are installed outside of the default MANPATH.
73 a517421f 2023-09-01 op Since they have a lot of clashes with "standard" command (like `exec'),
74 a517421f 2023-09-01 op define an alias to open specifically TCL8.6 man pages:
76 a517421f 2023-09-01 op alias tm='man -M /usr/local/lib/tcl/tcl8.6/man'
78 7b4d8efb 2022-02-04 op reset(1) doesn't work as expected inside tmux: the old output can still
79 7b4d8efb 2022-02-04 op be consulted when scrolling. If I, lazy as I am, bother to type "reset"
80 7b4d8efb 2022-02-04 op I want to be sure that the history was cleared!
82 7b4d8efb 2022-02-04 op if [ -n "$TMUX" ]; then
83 7b4d8efb 2022-02-04 op alias reset='reset && tmux clear-history'
86 7b4d8efb 2022-02-04 op CDPATH is super useful! I even wrote a post about it:
87 7b4d8efb 2022-02-04 op https://www.omarpolo.com/post/enjoying-cdpath.html
89 7b4d8efb 2022-02-04 op export CDPATH=".:$HOME/w:/usr/ports:/usr/ports/mystuff:$HOME/quicklisp/local-projects"
91 7b4d8efb 2022-02-04 op I love to hate gpg! It needs some special treatments to work and this
92 7b4d8efb 2022-02-04 op should also (finger crossed!) fix pinentry over ssh. I'm not sure it
93 7b4d8efb 2022-02-04 op works though, it's been a while since I've connected remotely to my
96 7b4d8efb 2022-02-04 op export GPG_TTY=$(tty)
97 7b4d8efb 2022-02-04 op if [ -n "$SSH_CONNECTION" ]; then
98 7b4d8efb 2022-02-04 op export PINENTRY_USER_DATA="USE_CURSES=1"
101 7b4d8efb 2022-02-04 op The BSDs have this incredibly useful signal available, it's a shame not
104 272ebe03 2022-09-16 op case "$(uname)" in
105 272ebe03 2022-09-16 op *BSD) stty status ^T ;;
108 7b4d8efb 2022-02-04 op I really like my prompt to be as minimal as possible. For some time
109 7b4d8efb 2022-02-04 op I've used a single colon `;' as prompt, it's really nice! At the moment
110 272ebe03 2022-09-16 op thought I'm usign a more plan9-esque percent sign, with an optional
113 272ebe03 2022-09-16 op if [ "$(hostname)" = venera ]; then
119 7b4d8efb 2022-02-04 op I got tired of trying to remember the set of flags for nc to walk to
120 7b4d8efb 2022-02-04 op Gemini servers, so here we are:
122 7b4d8efb 2022-02-04 op # "post" stdin to the gemini server
123 7b4d8efb 2022-02-04 op # usage: gem host [port]
126 7b4d8efb 2022-02-04 op host="${1:?missing host}"
127 7b4d8efb 2022-02-04 op port="${2:-1965}"
128 7b4d8efb 2022-02-04 op nc -c -Tnoverify "${host}" "${port}"
131 7b4d8efb 2022-02-04 op I think I've stolen these from someone. It makes a copy of the file and
132 7b4d8efb 2022-02-04 op launch an editor on the original file, incledibly useful when working
133 7b4d8efb 2022-02-04 op with ports (that's why doas!)
137 7b4d8efb 2022-02-04 op if [ -z "$1" ]; then
138 7b4d8efb 2022-02-04 op printf "%s\n" "USAGE: mgdiff file" >&2
141 029abbe3 2023-03-06 op doas cp -p "$1" "$1.orig.port"
145 7b4d8efb 2022-02-04 op hist is a quick wrapper around history and grep to quickly search for a
146 7b4d8efb 2022-02-04 op previous command:
150 7b4d8efb 2022-02-04 op if [ -z "$1" ]; then
151 7b4d8efb 2022-02-04 op printf "%s\n" "USAGE: hist pattern" >&2
154 7b4d8efb 2022-02-04 op history 0 | grep "$1"
157 04b39415 2022-02-04 op clbin (the site) is a web pastebin that's easy to use from the command
158 04b39415 2022-02-04 op line with curl. clbin (the function) is an easy way to share something,
159 04b39415 2022-02-04 op just pipe it to clbin and it returns an url.
163 04b39415 2022-02-04 op curl -F 'clbin=<-' https://clbin.com
166 7b4d8efb 2022-02-04 op Some aliases I use when working with the OpenBSD port tree:
168 7b4d8efb 2022-02-04 op alias m="make"
169 107df72f 2023-09-01 op alias mup="VISUAL=mg make update-patches"
170 7b4d8efb 2022-02-04 op alias mupl="make update-plist"
171 0d484cb2 2022-02-17 op alias mpldc="make port-lib-depends-check"
172 76902419 2022-03-30 op alias pbuild="env MAKE_JOBS=5 time make"
173 76902419 2022-03-30 op alias build="pbuild 2>&1 | tee build"
174 8a8ff32c 2022-02-05 op alias pclean='make clean="package plist"'
176 afa6a1ba 2022-05-23 op This one is pretty sophisticated, I've stolen it from jca@
178 afa6a1ba 2022-05-23 op # check shared libs version
183 afa6a1ba 2022-05-23 op for f in $(make show=SHARED_LIBS); do
184 afa6a1ba 2022-05-23 op [ "$((cnt++ % 2))" -eq 1 ] && continue
185 afa6a1ba 2022-05-23 op echo '===>' $f
186 afa6a1ba 2022-05-23 op /usr/src/lib/check_sym /usr/local/lib/lib$f.so* \
187 afa6a1ba 2022-05-23 op $(make show=WRKINST)/usr/local/lib/lib$f.so*
191 b73f39e1 2022-03-02 op And even more aliases:
193 b952b338 2024-03-05 op alias mopnew="mdirs ~/Maildir/op | grep -v rss | mlist -st | mthread -r | mseq -S"
195 b73f39e1 2022-03-02 op for c in com rep fwd bnc; do
196 e7f82226 2022-08-05 op local _mvisual='mg -f auto-fill-mode'
198 e7f82226 2022-08-05 op alias m$c="VISUAL='$_mvisual' m$c"
199 b73f39e1 2022-03-02 op alias o$c="m$c -from 'Omar Polo <op@openbsd.org>'"
202 76902419 2022-03-30 op And finally some aliases for mq
204 76902419 2022-03-30 op alias pnq="NQDIR=/tmp/ports/ nq "
205 76902419 2022-03-30 op alias pfq="NQDIR=/tmp/ports/ fq "
207 76902419 2022-03-30 op Stuff to use my own purritobin instance
209 76902419 2022-03-30 op : ${P_SERVER=paste.omarpolo.com}
210 76902419 2022-03-30 op : ${P_PORT=42069}
211 76902419 2022-03-30 op : ${P_TIME=week}
212 76902419 2022-03-30 op : ${P_MAXTIME=30}
214 76902419 2022-03-30 op shell client to upload a plaintext message
217 76902419 2022-03-30 op curl --silent --max-time "${P_MAXTIME}" \
218 76902419 2022-03-30 op --data-binary "@${1:-/dev/stdin}" \
219 76902419 2022-03-30 op "${P_SERVER}:${P_PORT}/${P_TIME}"
222 76902419 2022-03-30 op shell client to upload an encrypted message
225 76902419 2022-03-30 op key="$(openssl rand -hex 32)"
226 76902419 2022-03-30 op iv="$(openssl rand -hex 16)"
227 76902419 2022-03-30 op url="$(openssl enc -aes-256-cbc -K ${key} -iv ${iv} -e -base64 -A < ${1:-/dev/stdin} | purr)"
228 76902419 2022-03-30 op printf "%s\n" "${url%\/*}/paste.html#${url##*\/}_${key}_${iv}"
229 76902419 2022-03-30 op unset key iv url
232 76902419 2022-03-30 op ...and to decrypt it
236 76902419 2022-03-30 op baseurl="${url%\/*}"
237 76902419 2022-03-30 op vals="${url##*\#}"
238 76902419 2022-03-30 op paste=$(printf '%s\n' "${vals}" | cut -d_ -f1)
239 76902419 2022-03-30 op key=$(printf '%s\n' "${vals}" | cut -d _ -f2)
240 76902419 2022-03-30 op iv=$(printf '%s\n' "${vals}" | cut -d _ -f3)
241 76902419 2022-03-30 op curl --max-time "${P_MAXTIME}" --write-out "\n" --silent \
242 76902419 2022-03-30 op "${baseurl}/${paste}" | openssl enc -aes-256-cbc \
243 76902419 2022-03-30 op -base64 -d -K ${key} -iv ${iv}
244 76902419 2022-03-30 op unset url baseurl vals paste key iv
247 a6cd6375 2022-11-23 op llama is also nice. It's possible to use it to cd too!
250 a6cd6375 2022-11-23 op cd "$(llama "$@")"
253 7b7cd64a 2022-10-14 op For extra-comfyness bind it to C-o
255 a6cd6375 2022-11-23 op bind -m '^O=^U ll^M^Y'
257 7b4d8efb 2022-02-04 op find(1) is an invaluable tool and I use it all the time. walk is an
258 7b4d8efb 2022-02-04 op attempt to build a wrapper around some common usages of find that is a
259 7b4d8efb 2022-02-04 op little bit less verbose to use. The name is stolen from 9front, but the
260 7b4d8efb 2022-02-04 op implementation is completely different.
262 7b4d8efb 2022-02-04 op # usage: walk [dir] [type] [name regexp] [! command to execute]
265 7b4d8efb 2022-02-04 op if [ $# -eq 0 ]; then
272 7b4d8efb 2022-02-04 op local name=\*
274 7b4d8efb 2022-02-04 op if [ -n "$1" -a -d "$1" ]; then
280 7b4d8efb 2022-02-04 op b|c|d|f|l|p|s)
281 7b4d8efb 2022-02-04 op type="-type $1"
285 7b4d8efb 2022-02-04 op if [ -n "$1" -a "x$1" != "x!" ]; then
290 7b4d8efb 2022-02-04 op if [ "x$1" = x! ]; then
294 7b4d8efb 2022-02-04 op if [ $# -eq 0 ]; then
295 7b4d8efb 2022-02-04 op find "$dir" $type -iname "$name"
297 7b4d8efb 2022-02-04 op find "$dir" $type -iname "$name" -exec "$@" {} +
301 9ae7cc22 2024-03-05 op Sometimes it's useful to have a local postgresql database for testing. I've stolen this trick from
302 9ae7cc22 2024-03-05 op => https://jamey.thesharps.us/2019/05/29/per-project-postgres/ Jamey Thesharps "Per-project postgres" blog post
305 9ae7cc22 2024-03-05 op export PGDATA="$(pwd)/postgres"
306 9ae7cc22 2024-03-05 op export PGHOST="$PGDATA"
308 9ae7cc22 2024-03-05 op if [ ! -d "$PGDATA" ]; then
310 9ae7cc22 2024-03-05 op cat >> "$PGDATA/postgresql.conf" <<-EOF
311 9ae7cc22 2024-03-05 op listen_addresses = ''
312 9ae7cc22 2024-03-05 op unix_socket_directories = '$PGHOST'
314 9ae7cc22 2024-03-05 op echo "CREATE DATABASE $USER;" | postgres --single -E postgres