first-match() { local prog for prog in $@ if (( $+commands[$prog] ));then printf '%s\n' $prog break fi } export EDITOR=$(first-match nvim vim vi ed)