#!/bin/bash

B1=B
B2=("CHANGE DEFAULT EDITOR")

function change_editor {
    clear
    backup_conf ${HOME}/.bashrc
    EDITOR=${EDITOR:=vi}
    inputbox "Specify your favourite text editor
or hit enter for [${EDITOR}]"
    until [ $(which "${INPUT:=$EDITOR}" 2> /dev/null) ]; do
	inputbox "[${INPUT}] does not exist, try again"
    done

    [ "$RETVAL" != "0" ] && return

    if grep -q EDITOR ${HOME}/.bashrc; then
	sed "s|\<EDITOR=\"[0-9a-zA-Z]*\"|EDITOR=\"${INPUT:=$EDITOR}\"|" < ${HOME}/.bashrc > ${HOME}/.bashrc.tmp
	mv ${HOME}/.bashrc.tmp ${HOME}/.bashrc
    else
	echo -e "export EDITOR=\"${INPUT:=$EDITOR}\"" >> ${HOME}/.bashrc
    fi
    . ${HOME}/.bashrc
}
