diff options
author | Aaron LI <aly@aaronly.me> | 2019-06-24 22:18:22 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2019-06-24 22:18:22 +0800 |
commit | eb19fc16c9b59e79da9158f721c7584e831aaff3 (patch) | |
tree | 68233711a84c02881d68adeaa881d978da8074eb | |
parent | b54511e01e3b79799d61bb7c67aefb412d696328 (diff) | |
download | atoolbox-eb19fc16c9b59e79da9158f721c7584e831aaff3.tar.bz2 |
Add acme/a script to better start Acme editor
Credit: https://github.com/evbogdanov/acme
-rwxr-xr-x | acme/a | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -0,0 +1,71 @@ +#!/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 PAGER=nobs +export TERM=dumb +export tabstop=8 + +exec ${PLAN9}/bin/acme -a -f "${FONT}" "$@" |