config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 5725d32cb4d766005df210733a9b05f623e97e45
parent 9f0baf05f6420f0cf894a9034395ccd3579da613
Author: Jacob R. Edwards <n/a>
Date:   Wed,  2 Mar 2022 13:52:31 -0800

Make and use a meta-editor script

Many programs handle EDITOR and VISUAL differently, so this it's
always uniform (if EDITOR is respected, anyway): Terminal capabilities
are tested to see whether the dumb editor should be used or not.
Additionally an X11 editor can be set and will be used if possible.

Diffstat:
Alocal/bin/bin/edit | 28++++++++++++++++++++++++++++
Mlocal/rc/lib/profile | 8++++++--
2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/local/bin/bin/edit b/local/bin/bin/edit @@ -0,0 +1,28 @@ +#!/bin/sh +# Copyright 2022 Jacob R. Edwards +# Meta Editor +# +# On systems with X running, I like sam(1), +# On systems with "smart" terminals, I like vi(1), +# And on systems without "smart" terminals, I like ed(1) +# (I find sam without the terminal difficult, as it's not +# line based). +# +# This script performs various checks to see which editor should be +# used. Unfortunately the standard EDITOR and VISUAL variables can't +# be used since I want to use THIS as an editor. So set DUMB as +# your EDITOR, SMART as your VISUAL, and EXTERN as your X11 editor. + +if test "$EXTERN" -a "$DISPLAY" -a "$(id -u)" -ne 0 +then + exec "$EXTERN" "$@" +else + case "$TERM" in + (dumb) + exec "${DUMB:-ed}" "$@" + ;; + (*) + exec "${SMART:${DUMB:-vi}}" "$@" + ;; + esac +fi diff --git a/local/rc/lib/profile b/local/rc/lib/profile @@ -18,11 +18,15 @@ ifs = ' # Program Preferences BROWSER = glinks CC = tcc -EDITOR = ed +EDITOR = edit PAGER = cat SHELL = rc TERMINAL = 9term -VISUAL = sam + +# edit script editors +DUMB=ed +SMART=vi +EXTERN=sam # XDG Directories XDG_CACHE_HOME = $home/sys/cache