#!/bin/sh
#
# edit - find a sensible editor and use that to edit the file(s) supplied

for editor in nvim vim vi kak vis; do
  if command -v "${editor}" >/dev/null 2>&1; then
    "${editor}" "$@"
    rc="$?"
    # return code 127, if installation/launch failed
    # try next available editor
    if [ "${rc}" -ne 127 ]; then
      exit "${rc}"
    fi
  fi
done

printf '%s: no sensible editor found on this system.\n' "${0##*/}" >&2
exit 1
