Blob


1 # ksh
3 OpenBSD ksh (sometimes called opdksh or oksh) is the default shell on
4 OpenBSD, and is generally my go-to choince on other systems too. It has
5 a good ratio of features and simplicity
7 if [ "$TERM" = dumb ]; then
8 PS1='$ '
9 return
10 fi
12 Enable emacs-like command editing regardless of $EDITOR and csh-like
13 history expansion with !
15 set -o emacs
16 set -o csh-history
18 Talking about history, by default ksh won't store any, which is
19 unfortunate. I can't live without my C-r working!
21 HISTCONTROL=ignoredups:ignorespace
22 HISTFILE=$HOME/.history
23 HISTSIZE=10000
25 OpenBSD ksh has a limited support for programmed completions through
26 static lists. The completions are provided via an array called
27 complete_$progname; or complete_$progname_$nth for the nth argument.
29 Here's the completions for ssh and scp:
31 HOST_LIST=$(awk '/Host / {print $2}' ~/.ssh/config | xargs echo)
33 set -A complete_ssh -- $HOST_LIST
34 set -A complete_scp -- $HOST_LIST
36 and for kill(1) and pkill(1)
38 set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
39 set -A complete_pkill_2 -- -SIGHUP -SIGUSR1 -SIGUSR2 -SIGTERM -SIGKILL
41 and for vmd(8) if available
43 if pgrep -fq /usr/sbin/vmd; then
44 set -A complete_vmctl_1 -- console load reload start stop \
45 reset status send receive
46 set -A complete_vmctl -- \
47 $(vmctl status | awk '!/NAME/{printf "%s ", $NF}')
48 fi
50 and for ifconfig(8)
52 set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)
54 and for got(1)
56 set -A complete_got_1 -- \
57 init \
58 import im \
59 clone cl \
60 fetch fe \
61 checkout co \
62 update up \
63 status st \
64 log \
65 diff di \
66 blame bl \
67 tree tr \
68 ref \
69 branch br \
70 tag \
71 add \
72 remove rm \
73 revert rv \
74 commit ci \
75 send se \
76 cherrypick cy \
77 backout bo \
78 rebase rb \
79 histedit he \
80 integrate ig \
81 merge mg \
82 stage sg \
83 unstage ug \
84 cat \
85 info
87 Tweak the output of ls
89 alias ls='ls -F'
91 reset(1) doesn't work as expected inside tmux: the old output can still
92 be consulted when scrolling. If I, lazy as I am, bother to type "reset"
93 I want to be sure that the history was cleared!
95 if [ -n "$TMUX" ]; then
96 alias reset='reset && tmux clear-history'
97 fi
99 CDPATH is super useful! I even wrote a post about it:
100 https://www.omarpolo.com/post/enjoying-cdpath.html
102 export CDPATH=".:$HOME/w:/usr/ports:/usr/ports/mystuff:$HOME/quicklisp/local-projects"
104 I love to hate gpg! It needs some special treatments to work and this
105 should also (finger crossed!) fix pinentry over ssh. I'm not sure it
106 works though, it's been a while since I've connected remotely to my
107 desktop.
109 export GPG_TTY=$(tty)
110 if [ -n "$SSH_CONNECTION" ]; then
111 export PINENTRY_USER_DATA="USE_CURSES=1"
112 fi
114 The BSDs have this incredibly useful signal available, it's a shame not
115 to use it!
117 stty status ^T
119 I really like my prompt to be as minimal as possible. For some time
120 I've used a single colon `;' as prompt, it's really nice! At the moment
121 thought I'm usign a more plan9-esque percent sign:
123 PS1='% '
125 I got tired of trying to remember the set of flags for nc to walk to
126 Gemini servers, so here we are:
128 # "post" stdin to the gemini server
129 # usage: gem host [port]
130 gem()
132 host="${1:?missing host}"
133 port="${2:-1965}"
134 nc -c -Tnoverify "${host}" "${port}"
137 I think I've stolen these from someone. It makes a copy of the file and
138 launch an editor on the original file, incledibly useful when working
139 with ports (that's why doas!)
141 mgdiff()
143 if [ -z "$1" ]; then
144 printf "%s\n" "USAGE: mgdiff file" >&2
145 return
146 fi
147 doas cp -p "$1" "$1.orig"
148 doas mg "$1"
151 hist is a quick wrapper around history and grep to quickly search for a
152 previous command:
154 hist()
156 if [ -z "$1" ]; then
157 printf "%s\n" "USAGE: hist pattern" >&2
158 return 1
159 fi
160 history 0 | grep "$1"
163 Some aliases I use when working with the OpenBSD port tree:
165 alias m="make"
166 alias mup="make update-patches"
167 alias mupl="make update-plist"
168 alias build="MAKE_JOBS=5 time make 2>&1 | tee build"
169 alias pclear='make clean="package plist"'
171 find(1) is an invaluable tool and I use it all the time. walk is an
172 attempt to build a wrapper around some common usages of find that is a
173 little bit less verbose to use. The name is stolen from 9front, but the
174 implementation is completely different.
176 # usage: walk [dir] [type] [name regexp] [! command to execute]
177 walk()
179 if [ $# -eq 0 ]; then
180 find .
181 return
182 fi
184 local dir=.
185 local type=
186 local name=\*
188 if [ -n "$1" -a -d "$1" ]; then
189 dir="$1"
190 shift
191 fi
193 case "$1" in
194 b|c|d|f|l|p|s)
195 type="-type $1"
196 shift
197 esac
199 if [ -n "$1" -a "x$1" != "x!" ]; then
200 name="$1"
201 shift
202 fi
204 if [ "x$1" = x! ]; then
205 shift
206 fi
208 if [ $# -eq 0 ]; then
209 find "$dir" $type -iname "$name"
210 else
211 find "$dir" $type -iname "$name" -exec "$@" {} +
212 fi