#!/bin/bash run() { local prog="$1"; shift local args='' if [[ $# -gt 0 ]]; then printf -v args -- ' %q' "$@" fi eval exec -- "${prog}${args}" } { if [ -n "$DISPLAY" ]; then run "${VISUAL:-$SELECTED_EDITOR}" "$@" else run "${EDITOR:-$SELECTED_EDITOR}" "$@" fi } || run "${ALTERNATE_EDITOR:-false}" "$@"