#!/bin/sh # # Copyright (c) 2019 Aaron LI # MIT License # # Default font and size fontname=NotoSansMono-Regular fontsize=11 usage() { echo "usage: ${0##*/} [-f [fontname][:fontsize]] [acme_args ...]" >&2 echo "defaults: fontname: '${fontname}', fontsize: ${fontsize}" >&2 exit 1 } is_running() { pgrep -x -u "${USER}" "$1" >/dev/null 2>&1 } get_font() { local name size case $1 in *:*) name="${1%:*}" size="${1#*:}" ;; *) name="$1" ;; esac name="${name:-$2}" size="${size:-$3}" echo "/mnt/font/${name}/${size}a/font" } [ -n "${PLAN9}" ] || { echo "ERROR: Environment variable 'PLAN9' not set!" >&2 exit 2 } while getopts :f:h opt; do case ${opt} in f) font="${OPTARG}" ;; h) usage ;; \?) echo "Invalid option -${OPTARG}" >&2 usage ;; :) echo "Option -${OPTARG} requires an argument" >&2 usage ;; esac done shift $((${OPTIND} - 1)) FONT=$(get_font "${font}" ${fontname} ${fontsize}) is_running fontsrv || fontsrv & is_running plumber || plumber export TERM=dumb export SHELL="${PLAN9}/bin/rc" export PAGER="${PLAN9}/bin/nobs" exec ${PLAN9}/bin/acme -a -f "${FONT}" "$@"