-local p="ps -aSdxwwouser=USR -ogroup=GRP -opid,nice=N \
- -o%cpu,%mem,tt,stat,start=START -oetime,command | ${PAGER:-more} -Se"
+local p=
+if { which pstree >/dev/null 2>&1 && \
+ [[ ! "$(readlink -f $(which pstree))" =~ "/busybox" ]] } {
+ # use pstree, but NOT busybox pstree because it kinda sucks
+ p="pstree -wg3"
+} elif [[ "$OSTYPE" =~ '^freebsd' ]] {
+ p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
+ -o%cpu,%mem,tty,stat,start=START -oetime,command"
+} elif [[ "$(readlink -f $(which ps))" =~ "/busybox" ]] {
+ # busybox compatible
+ p="ps -eouser='USR ' -ogroup='GRP ' \
+ -opid=' PID' -onice=' NI' -ovsz=' MEM' \
+ -otty,stat,etime,comm"
+} else {
+ # XXX: untested, posix
+ # TODO: support gnu ps
+ p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
+ -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
+}
+p="$p | ${PAGER:-more} -Se"